Can the feature derive macro be applied only on functions and structures?

Asked 2 months ago, Updated 2 months ago, 3 views

I asked the same question on teratail, but I have not received an answer, so I will ask you the same question!

All of the information below is an abstraction of the story about this repository.
The repository contains folders named internal and external and feature.
I want to prevent external library users from using the public function written in the files in each folder unless the corresponding feature is on!

I wanted to separate the files under src of my lib project by function category.
If there were folders A and B, ideally if you specified features=["A"] on the user side of the library,

// Use LIBRARY_NAME::B::FUNCTION_NAME, etc. should not be allowed

I'd like to make it look like this.

Currently, the file structure is as follows:

src --
    |-- A
          |-- |--
          |-- |--
    |-- B
          |-- |--
          |-- |--

src/ is as follows:

pub mod A;

# [cfg(feature="B")]
pub mod B;

A/ is as follows:

pub mod A;
pubuse A::*;

B/ is similar to A as follows:

pub mod B;
pubuse B::*;

However, if you specify features=["A"] from the current user side,


You can use for some reason.
I understand that you can annotate #[cfg(feature="A")] on functions and structures one after another, but is there any easier way?


2022-09-30 14:12

1 Answers

It was resolved based on Pappy's
--no-default-features We have confirmed that it will become unusable by adding default-features=false to the flag or dependencies to disable the default feature.

2022-09-30 14:12

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.