This doesn't compile. The problem is the test line with crate::f32. Why does this work when called in main(), but doesn't work when called in tests? And why does it work for the other function but not for this one? Can someone please explain how these scopes work in this case?
f32 should not be prefixed with anything. Just doing f32::eval_expr_to_type should work, even in tests.
Note, you also need to import the relavant traits into the test module, in this case use crate::EvaluateExpression should do the tricks
error[E0599]: no function or associated item named `eval_expr_to_type` found for type `f32` in the current scope
--> src/lib.rs:35:22
|
35 | let x = f32::eval_expr_to_type(&"".to_string());
| ^^^^^^^^^^^^^^^^^ function or associated item not found in `f32`
|
= help: items from traits can only be used if the trait is in scope
= note: the following trait is implemented but not in scope; perhaps add a `use` for it:
`use crate::EvaluateExpression;`
This error can be fixed by following the instructions, import EvaluateExpression in the test module. Treat inline modules as being declared in a seperate file.
Well, this isn't casting anything (even though as is used), it just specifies which trait the function came from. Just in case multiple traits declare the same function.
Still. I just learned this whole thing a couple of hours ago. To me, it's new, because I'm a C++ guy and I would've done all that with a template. The idea that a trait can represent a primitive type is quite new to me