Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::string::String;
- static mut TAB: [&'static str; 2] = [
- "/// Data",
- "static TAB: &\'static [ &\'static str ] = &[",
- ];
- static mut TAB3: [&'static str; 4] = [
- "/// Data",
- "static TAB: &\'static [ &\'static str ]",
- ",jsfv,jbfckq.abdf.kjqbf",
- "ksdbf,jhsdbcvahjdvcmjcv,hja",
- ];
- static mut arr: [u8; 4] = [1, 2, 3, 4];
- fn main() {
- unsafe {
- println!("\nFirst Tab:");
- TAB.iter().all(|e| {
- println!("{}", e);
- true
- });
- TAB[0] = "hello"; // works great!
- println!("\nSecond Tab:");
- TAB.iter().all(|e| {
- println!("{}", e);
- true
- });
- let b: String = format!("let mut num: i8 = {};", arr[3]);
- let tab2: [String; 2] = [TAB[0].to_string(), b ]; // nope!
- println!("\nThird Tab:");
- tab2.iter().all(|e| {
- println!("{}", e);
- true
- });
- }
- unsafe {
- println!("\nFirst Tab3:");
- TAB3.iter().all(|e| {
- println!("{}", e);
- true
- });
- TAB3[2] = "hello"; // works great!
- println!("\nSecond Tab3:");
- TAB3.iter().all(|e| {
- println!("{}", e);
- true
- });
- let s: String = format!("let mut num: i8 = {};", arr[3]);
- //let tab2: [String; 2] = [TAB[0].to_string(), b ];
- let mut tab4: Vec<&str> = TAB3.iter().map(|&e| {
- e
- }).collect::<Vec<&str>>(); // work :blink_face
- // La solution ligne 60 fonctionne pour un tableau de quelques elements,
- // mais comment puis-je initialiser le tableau tab4 avec les valeurs du
- // tableau TAB3 pour ensuite faire `TAB[3] = b;` ?
- println!("\nThird Tab4:");
- tab4.iter().all(|e| {
- println!("{}", e);
- true
- });
- tab4[0] = &s;
- println!("\nThird Tab4_vec[0]:");
- tab4.iter().all(|e| {
- println!("{}", e);
- true
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement