Ask Your Question
4

What is the way to make a Rust object inaccessible within the crate, but accessible to the public outside of it?

asked 2023-02-06 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-01-11 13:00:00 +0000

lalupa gravatar image

To make a Rust object inaccessible within the crate, but accessible to the public outside it, you can use the pub keyword to make the object public, and then use the #[doc(hidden)] attribute to hide it from the crate's documentation.

For example, to create a struct named MyStruct that is only accessible from outside the crate, you would define it like this:

#[doc(hidden)]
struct MyStruct {
    // ...
}

pub struct VisibleStruct {
    // ...
}

In this example, MyStruct is marked with #[doc(hidden)], which means that it will not be included in the crate's documentation, but it is still accessible to code outside the crate that imports it. On the other hand, VisibleStruct is marked as pub, which means that it is accessible both inside and outside the crate.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-06 11:00:00 +0000

Seen: 10 times

Last updated: Jan 11 '23