mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-02-03 09:57:30 +02:00
20 lines
296 B
Markdown
20 lines
296 B
Markdown
|
# Structs
|
||
|
|
||
|
Like C and C++, Rust has support for custom structs:
|
||
|
|
||
|
```rust,editable
|
||
|
struct Person {
|
||
|
name: String,
|
||
|
age: u8,
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let peter = Person {
|
||
|
name: String::from("Peter"),
|
||
|
age: 27,
|
||
|
};
|
||
|
|
||
|
println!("{} is {} years old", peter.name, peter.age);
|
||
|
}
|
||
|
```
|