我正在尝试将一个拆分impl为不同的模块。子impl块中的项应可由父级访问impl,但实现的struct / enum用户不能公开访问。
这是我的尝试:
mod foo {
pub struct Foo {
field: String
}
impl Foo {
pub fn new() -> Foo {
Foo { field: "Joe".to_string() }
}
pub fn pubfn(&self) {
self.my_impl();
}
}
// Ideally, this should be in a separate file
mod foo_impl_details {
impl super::Foo {
// If I make this `pub`, it will be publicly visible to
// users of `Foo`, not just the impl block in `super` …Run Code Online (Sandbox Code Playgroud) rust ×1