Advertisement
NubeColectiva

100 veces array con Rust

Apr 21st, 2020
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.56 KB | None | 0 0
  1. // Crea un array con al menos 100 elementos en donde aparece `???`
  2.  
  3. // Hay una atajo para inicializar arrays con una cierto tamaño
  4. // que no requiere que escribas 100 items (pero puedes hacerlo si quiers).
  5. // Por ejemplo, puedes hacer:
  6. // let array = ["¿Ya llegamos?"; 10];
  7.  
  8. fn unsize<T>(x: &[T]) -> &[T] { x }
  9.  
  10. fn main() {
  11.     let a = ["¿Ya llegamos?"; 100];
  12.  
  13.     if a.len() >= 100 {
  14.         println!("{:?}", unsize(&a));
  15.         println!("Wow, that's a big array!");
  16.     } else {
  17.         println!("Meh, I eat arrays like that for breakfast.");
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement