Skip to content

Instantly share code, notes, and snippets.

@pramatias
Created July 22, 2020 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pramatias/e331a4f9df9b391ff8837daa62411938 to your computer and use it in GitHub Desktop.
Save pramatias/e331a4f9df9b391ff8837daa62411938 to your computer and use it in GitHub Desktop.
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