[−][src]Function tao_of_rust::ch03::traits::string_add
pub fn string_add()
trait: 关联类型String用法
说明:
在Rust标准库中,String
类型实现Add trait
,使用了关联类型。
如下所示:
impl Add<&str> for String { type Output = String; fn add(mut self, other: &str) -> String { self.push_str(other); self } }Run
Base usage:
let a = "hello"; let b = " world"; let c = a.to_string() + b; println!("{:?}", c); // "hello world"Run