I would like an attribute, e.g., called private_new, that limits the visibility of the generated new() function.
I want to use this to limit where a newtype can be instantiated.
Example:
mod inner {
pub struct Foobar {
// some fields etc.
}
#[nutype(private_new)] // <- new attribute used here
pub struct TaggedFoobar(Foobar);
pub fn get_tagged_foobar() -> TaggedFoobar {
let foobar = get_foobar_from_somewhere();
// `new` should only be callable here, so that `TaggedFoobar` is guaranteed to originate from this fn!
TaggedFoobar::new(foobar)
}
}
use inner::*;
fn should_not_compile() -> TaggedFoobar {
let foobar = get_foobar_from_somewhere();
// !! This should not compile, because `new` is private/not visible here !!
TaggedFoobar::new(foobar)
}