Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #[derive(Debug)]
  2. struct TestError {
  3. test: String,
  4. }
  5.  
  6. impl std::fmt::Display for TestError {
  7. fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
  8. write!(
  9. f,
  10. "TestError::Display test: {}",
  11. self.test,
  12. )
  13. }
  14. }
  15.  
  16. impl std::error::Error for TestError {
  17. fn description(&self) -> &str {
  18. "TestError::description"
  19. }
  20. }
  21.  
  22. fn return_error() -> Result<(), TestError> {
  23. Err(TestError{ test: "return_error".to_string() })
  24. }
  25.  
  26. fn main() {
  27. println!("{}", return_error().err().unwrap());
  28. println!("{:?}", return_error().err().unwrap());
  29. return_error().expect("expect in main");
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement