![](https://i0.wp.com/media.dev.to/cdn-cgi/image/width=1000,height=500,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi8vomntbpblzz0jnvums.png?w=1200&ssl=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),
};
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)=>{ }
}