update at 2020-06-16 18:18:40 by ehlxr
parent
4c9a6dec3c
commit
939f409503
25
src/main.rs
25
src/main.rs
|
@ -937,7 +937,7 @@ fn main() {
|
|||
println!("{}", s);
|
||||
let mut s: String = "Hello".to_string();
|
||||
let w = "World";
|
||||
s.push_str(w);// 并不需要获取 w 的所有权
|
||||
s.push_str(w); // 并不需要获取 w 的所有权
|
||||
s.push('!');
|
||||
println!("{} {}", s, w);
|
||||
|
||||
|
@ -951,15 +951,18 @@ fn main() {
|
|||
// println!("{} {} {}", s1, s3, s2);
|
||||
println!("{} {}", s3, s2);
|
||||
|
||||
for c in "नमˑे".chars() {
|
||||
println!("{}", c);
|
||||
let hello = "测试中文字符串";
|
||||
for c in hello.chars() {
|
||||
print!("{} ", c);
|
||||
}
|
||||
for b in "नमˑे".bytes() {
|
||||
println!("{}", b);
|
||||
println!("");
|
||||
for b in hello.bytes() {
|
||||
print!("{} ", b);
|
||||
}
|
||||
let hello = "Здравствуйте";
|
||||
let s = &hello[0..4];
|
||||
println!("&hello[0..4]={}", s);
|
||||
println!("");
|
||||
// let s = hello[1]; // Rust 的字符串不支持索引
|
||||
// let s = &hello[0..4]; // thread 'main' panicked at 'byte index 4 is not a char boundary; it is inside '试' (bytes 3..6) of `测试中文字符串`', src/libcore/str/mod.rs:2219:5
|
||||
print!("{}", &hello[0..3]);
|
||||
}
|
||||
|
||||
fn test_tuple(t: (i32, &str)) {
|
||||
|
@ -1265,7 +1268,7 @@ impl ToString for Tweet {
|
|||
//}
|
||||
|
||||
fn notify<T, U>(t: &T, u: &U) -> String
|
||||
where
|
||||
where
|
||||
T: Summary + ToString,
|
||||
U: Summary,
|
||||
{
|
||||
|
@ -1335,7 +1338,7 @@ fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
|
|||
}
|
||||
|
||||
struct Cacher<T, D, F>
|
||||
where
|
||||
where
|
||||
T: Fn(&D) -> F,
|
||||
{
|
||||
calculation: T,
|
||||
|
@ -1343,7 +1346,7 @@ struct Cacher<T, D, F>
|
|||
}
|
||||
|
||||
impl<T, D, F> Cacher<T, D, F>
|
||||
where
|
||||
where
|
||||
D: Hash + Eq,
|
||||
F: Copy,
|
||||
T: Fn(&D) -> F,
|
||||
|
|
Loading…
Reference in New Issue