Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #[derive(Debug)]
  2. pub enum MyStrError {
  3. MyStrErrorVariant(String),
  4. }
  5.  
  6. pub enum MyIntError {
  7. MyIntErrorVariant(i32),
  8. }
  9.  
  10. impl From<MyIntError> for MyStrError {
  11. fn from(_e: MyIntError) -> Self {
  12. MyStrError::MyStrErrorVariant("Converted an int to a string".to_string())
  13. }
  14. }
  15.  
  16. fn error_function() -> Result<(), MyIntError> {
  17. Err(MyIntError::MyIntErrorVariant(12345))
  18. }
  19.  
  20. fn converting_function() -> Result<(), MyStrError> {
  21. // doesn't compile:
  22. error_function()
  23. // compiles:
  24. //Ok(error_function()?)
  25. }
  26.  
  27. fn main() {
  28. println!("{:?}", converting_function());
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement