Rust: Struct with impl
A short, tested Rust example for struct with impl. Copy it and adjust the names and paths for your project.
Rust
struct User {
name: String,
age: u32,
}
impl User {
fn new(name: &str, age: u32) -> Self {
Self { name: name.to_string(), age }
}
fn greet(&self) -> String {
format!("Hi, {}", self.name)
}
}Find it in Zest
Search for “rust struct with impl” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.