[rust-dev] wrapping a C library (ownership/mutability questions)

Alex Crichton alex at crichton.co
Sat Jan 18 22:54:51 PST 2014


> Any way to prevent this, so that only I am allowed to create FieldDef
> structs but can still return references to them in my public API?

You'll want something like:

pub struct FieldDef {
    priv field: int,
}

That way everyone can name your struct, but no one other than you can
construct it because it has private fields.


More information about the Rust-dev mailing list