跳至主要內容

乱堆的不想整理

黑静美...小于 1 分钟

乱堆的不想整理

#[derive(Debug)]  //idiot programm 
struct Person<'a>{   //todo have to declare the lifetime
// struct person{  /*todo can not directly be writed down in this form*/
//     name: &str
    name: &'a str,
    color: String,
    age: u8,
}

fn main() {
    // String::from
    let name = String::from("Value C++");
    /* Literals of the text : &str
                            -> String */
    //.to_owned()
    //.to_string()
    let course = "Rust";
    let course = "Rust".to_owned();
let new_name = name.replace("c++","cpp");
println!("{name}; {new_name}\n{course}");

let rust = "\x52\x75\x73\x74";
println!("{rust}");
let rust = "\x52\x75\x73\x74".to_string();
println!("{rust}");

let name ="Tsing";
let color = "blue".to_string();
let people = Person{
    name: name,//name behind: name declared in this fn
    /* name in the front: name in struct*/
    color: color,
    // color: "blue",
    /*        ^^^^^^- help: try using a conversion method: `.to_string()`
    |         |
    |         expected `String`, found `&str`*/

    age: 9,
};
println!("{:?}", people)};  //#[derive(Debug)] 后可以打印,否则不行
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v3.1.3