mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
14 lines
284 B
14 lines
284 B
3 years ago
|
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() returns the length of a String
|
||
|
|
||
|
(s, length)
|
||
|
}
|