Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)]
- struct TestError {
- test: String,
- }
- impl std::fmt::Display for TestError {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- write!(
- f,
- "TestError::Display test: {}",
- self.test,
- )
- }
- }
- impl std::error::Error for TestError {
- fn description(&self) -> &str {
- "TestError::description"
- }
- }
- fn return_error() -> Result<(), TestError> {
- Err(TestError{ test: "return_error".to_string() })
- }
- fn main() {
- println!("{}", return_error().err().unwrap());
- println!("{:?}", return_error().err().unwrap());
- return_error().expect("expect in main");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement