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