Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement