the.bay.news

Into and As and Generic Type Constraints

The Rust Programming Language Forum
Into and As and Generic Type Constraints
hi, I'm having trouble with type constraints. In this example into() fails but casting with as works: fn example() { let a: u64 = 0; let b: f64 = a.into(); // Error - From<u64> not satisifed let c: f64 = a as f64; // Works } I have a generic function, but it's wrong because you can't cast to and from f64: fn example_generic<T>(v: T) -> T where T: Into<f64>, f64: Into<T>, { let x: f64 = v.into(); x.into() } Since as works, is it possible to add a type constraint ...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.