[−][src]Function tao_of_rust::ch06::functions::method_and_function
pub fn method_and_function()
方法与函数
Base usage: 泛型函数可推断类型
#[derive(Debug)] struct User { name: &'static str, avatar_url: &'static str, } impl User { fn show(&self) { println!("name: {:?} ", self.name); println!("avatar: {:?} ", self.avatar_url); } } fn main() { let user = User { name: "Alex", avatar_url: "https://avatar.com/alex" }; // User::show(&user) user.show(); }Run