I have a simple struct which I want to make public, but I want to restrict how users can construct it.
So I have something like this:
struct Foo {
bar: u16
}
I have then defined a constructor using the new
convention:
impl Foo {
fn new(bar: u16) -> Option<Foo> {
// .. implementation
}
I only want users to use my new
constructor, not the default like this:
Foo { bar: 12 }
Is this possible? I'm wondering if it's as simple as marking bar
as private, but intuitively that doesn't seem correct.