Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1.  
  2. use std::string::String;
  3.  
  4.  
  5. static mut TAB: [&'static str; 2] = [
  6. "/// Data",
  7. "static TAB: &\'static [ &\'static str ] = &[",
  8. ];
  9.  
  10. static mut TAB3: [&'static str; 4] = [
  11. "/// Data",
  12. "static TAB: &\'static [ &\'static str ]",
  13. ",jsfv,jbfckq.abdf.kjqbf",
  14. "ksdbf,jhsdbcvahjdvcmjcv,hja",
  15. ];
  16.  
  17. static mut arr: [u8; 4] = [1, 2, 3, 4];
  18.  
  19. fn main() {
  20. unsafe {
  21. println!("\nFirst Tab:");
  22. TAB.iter().all(|e| {
  23. println!("{}", e);
  24. true
  25. });
  26.  
  27. TAB[0] = "hello"; // works great!
  28.  
  29. println!("\nSecond Tab:");
  30. TAB.iter().all(|e| {
  31. println!("{}", e);
  32. true
  33. });
  34.  
  35. let b: String = format!("let mut num: i8 = {};", arr[3]);
  36. let tab2: [String; 2] = [TAB[0].to_string(), b ]; // nope!
  37.  
  38. println!("\nThird Tab:");
  39. tab2.iter().all(|e| {
  40. println!("{}", e);
  41. true
  42. });
  43. }
  44.  
  45. unsafe {
  46. println!("\nFirst Tab3:");
  47. TAB3.iter().all(|e| {
  48. println!("{}", e);
  49. true
  50. });
  51.  
  52. TAB3[2] = "hello"; // works great!
  53.  
  54. println!("\nSecond Tab3:");
  55. TAB3.iter().all(|e| {
  56. println!("{}", e);
  57. true
  58. });
  59.  
  60. let s: String = format!("let mut num: i8 = {};", arr[3]);
  61. //let tab2: [String; 2] = [TAB[0].to_string(), b ];
  62.  
  63. let mut tab4: Vec<&str> = TAB3.iter().map(|&e| {
  64. e
  65. }).collect::<Vec<&str>>(); // work :blink_face
  66.  
  67. // La solution ligne 60 fonctionne pour un tableau de quelques elements,
  68. // mais comment puis-je initialiser le tableau tab4 avec les valeurs du
  69. // tableau TAB3 pour ensuite faire `TAB[3] = b;` ?
  70.  
  71. println!("\nThird Tab4:");
  72. tab4.iter().all(|e| {
  73. println!("{}", e);
  74. true
  75. });
  76.  
  77. tab4[0] = &s;
  78.  
  79. println!("\nThird Tab4_vec[0]:");
  80. tab4.iter().all(|e| {
  81. println!("{}", e);
  82. true
  83. });
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement