小编Att*_*ika的帖子

是否可以将展示广告拆分为不同的模块?

我正在尝试将一个拆分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

6
推荐指数
2
解决办法
1959
查看次数

标签 统计

rust ×1