这个有意思,指针解释获新生!!!
fn main() {
let mut s = String::
from(
"hello");
s.push_str(", world!");
println!(
"{}", s);
let s1 = String::
from(
"hello");
let (s2, len) =
calculate_len(s1);
println!(
"The len of '{}' is {}.", s2, len);
let s1 = String::
from(
"hello");
let len = calculate_length(&
s1);
println!(
"The length of '{}' is {}.", s1, len);
}
fn calculate_len(s: String) ->
(String, usize) {
let length =
s.len();
(s, length)
}
fn calculate_length(s: &String) ->
usize {
s.len()
}
转载于:https://www.cnblogs.com/aguncn/p/11397293.html
相关资源:JAVA上百实例源码以及开源项目
转载请注明原文地址: https://mac.8miu.com/read-73510.html