mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-04-22 05:18:04 +08:00
14 lines
278 B
Rust
Executable File
14 lines
278 B
Rust
Executable File
fn main() {
|
|
let s1 = String::from("hello");
|
|
|
|
let (s2, len) = calculate_length(s1);
|
|
|
|
println!("The length of '{}' is {}.", s2, len);
|
|
}
|
|
|
|
fn calculate_length(s: String) -> (String, usize) {
|
|
let length = s.len(); // len() 返回字符串的长度
|
|
|
|
(s, length)
|
|
}
|