SHARE
TWEET

Untitled

a guest Aug 21st, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::convert::TryFrom;
  2.  
  3.  
  4. struct CourseResult {
  5.     // a complex struct
  6.     // with lots of Option<T>
  7.     description: Option<String>
  8. }
  9.  
  10. struct Ttem {
  11.     // another complex struct
  12. }
  13.  
  14. #[derive(Debug)]
  15. struct ItemCreationError<'a> {
  16.     msg: &'a str,
  17. }
  18.  
  19. impl<'a> TryFrom<&'a CourseResult> for Item {
  20.     type Error = ItemCreationError<'a>;
  21.     fn try_from(course: &CourseResult) -> Result<Self, Self::Error> {
  22.         let _desc = course.description.ok_or(ItemCreationError { msg: "AAAHHH" })?;
  23.     }
  24. }
  25.  
  26. fn main() {
  27.     let courses : CourseResult = ....,
  28.     let item = Item::try_from(courses);
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top