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
fnmain(){let n:i16 = 256;let n:u8 = match n.try_into(){Ok(n) => n,Err(e) => {println!("there is an error when converting: {:?}, but we catch it", e.to_string());0}};assert_eq!(n, 0);println!("Success!")}
报错如下:
error[E0599]: no method named `try_into` found fortype `i16`in the current scope
--> main.rs:4:25
|
4 |let n: u8 = match n.try_into() {
| ^^^^^^^^ method not found in`i16`|
::: C:\Users\lde1wx\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\convert\mod.rs:569:8
|
569 | fn try_into(self) -> Result<T, Self::Error>;| -------- the method is available for`i16` here
|
= help: items from traits can only be used if the trait is in scope
= note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
help: the following trait is implemented but not in scope; perhaps add a `use`for it:
|
1 + use std::convert::TryInto;|
error: aborting due to previous error
For more information about this error, try `rustc --explain E0599`.
rustc 1.74.0 (79e9716c9 2023-11-13)
The text was updated successfully, but these errors were encountered:
https://zh.practice.rs/type-conversions/from-into.html#tryfromtryinto
报错如下:
rustc 1.74.0 (79e9716c9 2023-11-13)
The text was updated successfully, but these errors were encountered: