摘要: &str 字符串 直接声明时,生命周期为整个程序,直接写进了二进制中,类型为&'static str',意为字符串字元有一个叫static的生命期 借用str 作为String的引用来使用,无生命期,例如 fn print_str(my_str: &str){},调用为print_str(&Stri 阅读全文
posted @ 2023-03-22 15:16 摧残一生 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 链式方法 collect let new_vec = (1..=10).collect::<Vec>(); OR let new_vec: Vec = (1..=10).collect(); Vec![].into_iter().skip(3).take(4).collect::<Vec>(); s 阅读全文
posted @ 2023-03-22 15:01 摧残一生 阅读(36) 评论(0) 推荐(0) 编辑
摘要: u16::checked_add(251, 8).unwrap(); /* checked_add的方式有两种 第一种为u16::checked_add(数值,数值),相加 第二种类型直接调用checked_add() checked_*:返回的类型是Option<_>,当出现溢出的时候,返回值是N 阅读全文
posted @ 2023-03-22 14:59 摧残一生 阅读(175) 评论(0) 推荐(0) 编辑