You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0599]: no method named `unwrap` found for type `u32` in the current scope
--> src/main.rs:3:31
|
3 | let b: u32 = cast::u32(a).unwrap();
| ^^^^^^
error[E0308]: mismatched types
--> src/main.rs:6:21
|
6 | let _e: usize = cast::usize(c);
| ^^^^^^^^^^^^^^ expected usize, found enum `std::result::Result`
|
= note: expected type `usize`
found type `std::result::Result<usize, cast::Error>`
because the Output types use Result or not depending on the target's usize size.
Is there a way to write code that does checked (when needed) casts between fixed-sized types and usize that works on both 32-bit and 64-bit platforms?
I might be looking for something returning a Result on both, relying on inlining and optimization to eliminate the overhead in cases where the conversion turns out to be trivial.
The text was updated successfully, but these errors were encountered:
The following code compiles on 64-bit targets:
However, it doesn't compile on a 32-bit target:
because the
Output
types useResult
or not depending on the target'susize
size.Is there a way to write code that does checked (when needed) casts between fixed-sized types and
usize
that works on both 32-bit and 64-bit platforms?I might be looking for something returning a
Result
on both, relying on inlining and optimization to eliminate the overhead in cases where the conversion turns out to be trivial.The text was updated successfully, but these errors were encountered: