Generic pair class

Almost. I’d write it like this: public class Pair<F, S> { private F first; //first member of pair private S second; //second member of pair public Pair(F first, S second) { this.first = first; this.second = second; } public void setFirst(F first) { this.first = first; } public void setSecond(S second) { this.second = second; … Read more

Is there any trait that specifies numeric functionality?

You can use num or num-traits crates and bound your generic function type with num::Float, num::Integer or whatever relevant trait: use num::Float; // 0.2.1 fn main() { let f1: f32 = 2.0; let f2: f64 = 3.0; let i1: i32 = 3; println!(“{:?}”, sqrt(f1)); println!(“{:?}”, sqrt(f2)); println!(“{:?}”, sqrt(i1)); // error } fn sqrt<T: Float>(input: T) … Read more