&str
, String
. , , . : String
.
String
.
String
, . String
, , .
, , , .
. . , , . , , .
:
fn hello_string(x: &str) -> &str {
return "hello world";
}
&str
. - , , ? , , ?
, , . "hello world"
&'static str
, , . , , , main
.
fn hello_string(x: &str) -> &str
fn hello_string<'a>(x: &'a str) -> &'a str
. , , . , .
, :
fn long_string(x: &str) -> &str {
if x.len() > 10 {
"too long"
} else {
x
}
}
String
. String
, :
fn hello_string(x: &str) -> &str {
&String::from("hello world")
}
: " ". , , , . "" (, , ).