Advertisement
wswartzendruber

Accepting &str and String

Sep 3rd, 2022
1,698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.74 KB | None | 0 0
  1. #[cfg(test)]
  2. mod tests {
  3.  
  4.     struct Inmate {
  5.         name: String,
  6.         infraction: String,
  7.         incarceration_years: u16
  8.     }
  9.  
  10.     impl Inmate {
  11.  
  12.         fn new<IntoString: Into<String>>(
  13.             name: IntoString,
  14.             infraction: IntoString,
  15.             incarceration_years: u16,
  16.         ) -> Self {
  17.             Self {
  18.                 name: name.into(),
  19.                 infraction: infraction.into(),
  20.                 incarceration_years,
  21.             }
  22.         }
  23.     }
  24.  
  25.     #[test]
  26.     fn incarcerates() {
  27.        
  28.         let inmates = vec![
  29.             Inmate::new("LonghornAR", "maga", 20),
  30.             Inmate::new("wswartzendruber", "maga", 20),
  31.         ];
  32.  
  33.         assert_eq!(2, inmates.len());
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement