Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. fn strpos(a: &str, b: &str) -> StringPosition {
  2. b.find(a)
  3. .map_or_else(
  4. || StringPosition::NotFound,
  5. |pos: usize| StringPosition::Found(pos)
  6. )
  7. }
  8.  
  9. enum StringPosition {
  10. Found(usize),
  11. NotFound,
  12. }
  13.  
  14. fn main() {
  15. match strpos(&"World", &"Hello World") {
  16. StringPosition::Found(pos) => println!("substring found at position {}", pos),
  17. StringPosition::NotFound => println!("substring not found"),
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement