Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::convert::TryFrom;
- struct CourseResult {
- // a complex struct
- // with lots of Option<T>
- description: Option<String>
- }
- struct Ttem {
- // another complex struct
- }
- #[derive(Debug)]
- struct ItemCreationError<'a> {
- msg: &'a str,
- }
- impl<'a> TryFrom<&'a CourseResult> for Item {
- type Error = ItemCreationError<'a>;
- fn try_from(course: &CourseResult) -> Result<Self, Self::Error> {
- let _desc = course.description.ok_or(ItemCreationError { msg: "AAAHHH" })?;
- }
- }
- fn main() {
- let courses : CourseResult = ....,
- let item = Item::try_from(courses);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement