Created
July 22, 2020 02:39
-
-
Save pramatias/e331a4f9df9b391ff8837daa62411938 to your computer and use it in GitHub Desktop.
This file contains 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
struct AbPairs { | |
word : String, | |
abbreviation : String | |
} | |
struct SmallStr { | |
small_str: String | |
} | |
impl SmallStr { | |
fn import_from_str(&self, str: String) -> Option < SmallStr> { | |
let a = SmallStr { | |
small_str: str, | |
}; | |
let check_length = | |
if a.small_str.len() < 10 { | |
Some(a)} | |
else { None }; | |
return check_length; | |
} | |
} | |
fn main() { | |
let pairs = vec![ | |
AbPairs { word : "words".to_string() , | |
abbreviation : "words".to_string() } , | |
AbPairs { word : "hugebigword".to_string() , | |
abbreviation : "bgwrd".to_string() } , | |
AbPairs { word : "veryhugebigword".to_string() , | |
abbreviation : "vrbgwrd".to_string() }, | |
AbPairs { word : "hugellybigestword".to_string() , | |
abbreviation : "hgbgwrd".to_string() } | |
]; | |
let mut b = "hugebigwo".to_string(); | |
let mut a = SmallStr{ small_str : b}; | |
match a.import_from_str(b){ | |
Some(String) => println!("success"), | |
None => None | |
} | |
//println!("{}" , a.small_str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment