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::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
| 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
| fn main() { | |
| let array_str = ["a", "b", "c"]; | |
| let array_string = ["a".to_string(), "b".to_string(), "c".to_string()]; | |
| let value_str = "b"; | |
| let value_string = String::from(value_str); | |
| let result_str = array_str.contains(&value_string); | |
| let result_string = array_string.contains(&value_str); | |
| let result_literal = array_string.contains("b"); |
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() { | |
| let hs_str: HashSet<&str> = ["a", "b", "c"].iter().copied().collect(); | |
| let hs_string: HashSet<String> = vec!["a".to_string(), "b".to_string(), "c".to_string()] | |
| .into_iter() | |
| .collect(); | |
| let value_str = "b"; | |
| let value_string = String::from(value_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; | |
| fn contains<T, Q>(arr: &HashSet<T>, value: &Q) -> bool | |
| where | |
| T: std::cmp::PartialEq<Q>, | |
| { | |
| arr.iter().any(|v| v == value) | |
| } | |
| fn main() { |