Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn strpos(a: &str, b: &str) -> StringPosition {
- b.find(a)
- .map_or_else(
- || StringPosition::NotFound,
- |pos: usize| StringPosition::Found(pos)
- )
- }
- enum StringPosition {
- Found(usize),
- NotFound,
- }
- fn main() {
- match strpos(&"World", &"Hello World") {
- StringPosition::Found(pos) => println!("substring found at position {}", pos),
- StringPosition::NotFound => println!("substring not found"),
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement