Guest User

Untitled

a guest
Feb 16th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. pub struct Element {
  2. lol: i32,
  3. }
  4.  
  5. pub struct Container {
  6. element: Option<Element>,
  7. }
  8.  
  9. pub struct Error {
  10. text: &'static str,
  11. }
  12.  
  13. fn test<'a, I>(containers: I)
  14. where
  15. I: Iterator<Item = Option<&'a Container>>,
  16. {
  17. containers.map(|container| {
  18. let element = container
  19. .ok_or(Error {
  20. text: "container not found",
  21. })?
  22. .element
  23. .as_ref()
  24. .ok_or(Error { text: "no element" })?;
  25.  
  26. Ok::<_, Error>(element)
  27. });
  28. }
Add Comment
Please, Sign In to add comment