Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created December 31, 2019 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rust-play/cb367e6dadb9c7bf0d3692a432d5b09c to your computer and use it in GitHub Desktop.
Save rust-play/cb367e6dadb9c7bf0d3692a432d5b09c to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![allow(unused)]
trait Foo {
fn bar(&self);
fn baz(&self);
}
struct MyStruct;
impl Foo for MyStruct {
fn bar(&self) {
let mut d = vec!["a", "b", "c", "d","e","f","g","h", "i", "l", "m"];
d.sort_by(|a, b| a.partial_cmp(b).unwrap());
let mut s = vec!["c", "b", "a"];
s.sort_by(|a, b| a.partial_cmp(b).unwrap());
let u = d.clone().into_iter()
.map(|x| s.binary_search(&x).and_then(|i| d.get(i).ok_or(0))).map(|y|y.unwrap_or(&" ")).collect::<Vec<_>>();
println!("==> {:#?}", u);
}
fn baz(&self) {
// let's not worry about implementing baz() for now
todo!();
}
}
fn main() {
let s = MyStruct;
s.bar();
// we aren't even using baz() yet, so this is fine.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment