This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn contains<T, Q>(arr: &[T], value: &Q) -> bool | |
where | |
T: std::cmp::PartialEq<Q>, | |
{ | |
arr.iter().any(|v| v == value) | |
} | |
fn main() { | |
let array_str = ["a", "b", "c"]; | |
let array_string = ["a".to_string(), "b".to_string(), "c".to_string()]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops::Deref; | |
use rand; // 0.7.3 | |
use rand::Rng; | |
#[derive(Debug, PartialEq)] | |
struct Wrap<T> { | |
inside: T | |
} | |
impl<T> Wrap<T> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand; // 0.7.3 | |
use rand::Rng; | |
fn make_a_string() -> String { | |
let mut s = String::new(); | |
s.push_str("Hello World"); | |
let mut rng = rand::thread_rng(); | |
let r = rng.gen_range(0, 100); | |
for _ in 0..r { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand; // 0.7.3 | |
use rand::Rng; | |
fn make_a_string_with(string: &str) -> String { | |
let mut s = String::new(); | |
s.push_str(string); | |
let mut rng = rand::thread_rng(); | |
let r = rng.gen_range(0, 100); | |
for _ in 0..r { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand; // 0.7.3 | |
use rand::Rng; | |
fn make_a_string_with(string: &str) -> String { | |
let mut s = String::new(); | |
s.push_str(string); | |
let mut rng = rand::thread_rng(); | |
let r = rng.gen_range(0, 100); | |
for _ in 0..r { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand; // 0.7.3 | |
use rand::Rng; | |
fn make_a_string_with(string: &str) -> String { | |
let mut s = String::new(); | |
s.push_str(string); | |
let mut rng = rand::thread_rng(); | |
let r = rng.gen_range(0, 100); | |
for _ in 0..r { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand; // 0.7.3 | |
use rand::Rng; | |
fn make_a_string() -> String { | |
let mut s = String::new(); | |
s.push_str("Hello World"); | |
let mut rng = rand::thread_rng(); | |
let r = rng.gen_range(0, 100); | |
for _ in 0..r { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashSet; | |
fn main() { | |
// move strings into HashSet | |
let known_values: HashSet<&str> = ["a", "b", "c"] | |
.iter().cloned().collect(); | |
// provided an Vec<String> | |
let provided_values: Vec<String> = vec![ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashSet; | |
#[derive(Debug)] | |
enum Check<'a> { | |
Known(&'a str), | |
Duplicate(&'a str), | |
Missing(&'a str), | |
Unknown(&'a str) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashSet; | |
use std::rc::Rc; | |
#[derive(Debug)] | |
enum Check { | |
Known(Rc<String>), | |
Duplicate(Rc<String>), | |
Missing(Rc<String>), | |
Unknown(Rc<String>) |