A unit struct is a struct with no fields. It’s just a type.
I use this sometimes for organizing functions, e.g.,
struct Math;
impl Math {
fn add(a: i32, b: i32) -> i32 { a + b }
}
fn main() {
println!("{}", Math::add(1, 2));
}A unit struct is a struct with no fields. It’s just a type.
I use this sometimes for organizing functions, e.g.,
struct Math;
impl Math {
fn add(a: i32, b: i32) -> i32 { a + b }
}
fn main() {
println!("{}", Math::add(1, 2));
}