Rust type Result

  1. type Result is enum
pub enum Result<T, E> { /// Contains the success value #[lang = "Ok"] #[stable(feature = "rust1", since = "1.0.0")] Ok(#[stable(feature = "rust1", since = "1.0.0")] T), /// Contains the error value #[lang = "Err"] #[stable(feature = "rust1", since = "1.0.0")] Err(#[stable(feature = "rust1", since = "1.0.0")] E),
};
Enter fullscreen mode
Exit fullscreen mode

let me create a function that returntype is Result

fn test(path:String)->Result<&str,&str> { if path == "d" { Ok("我是成功了") }else{ Error("我失败了") } } match test { Ok(s) =>{ }, Error(x)=>{ }
}
Enter fullscreen mode
Exit fullscreen mode

Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
The technical storage or access that is used exclusively for statistical purposes. Free 2025 jamb questions and answers and answers cbt / jamb 2025 answers and answers cbt. Importance of user centric design in mobile app development.