Attribute Macro docify::export

source ·
Expand description

Marks an item for export, making it available for embedding as a rust doc example via docify::embed!(..) or docify::embed_run!(..).

By default, you can just call the attribute with no arguments like the following:

mod some_item {
    fn some_func() {
        println!("hello world");

When you docify::embed!(..) this item, you will have to refer to it by the primary ident associated with the item, in this case some_item. In some cases, such as with impl statements, there is no clear main ident. You should handle these situations by specifying an ident manually (not doing so will result in a compile error):

impl SomeTrait for Something {
    // ...

You are also free to specify an alternate export name for items that do have a clear ident if you need/want to:

fn hello_world() {

When you go to docify::embed!(..) or docify::embed_run!(..) such an item, you must refer to it by SomeName (in this case), or whatever name you provided to #[docify::export].

There is no guard to prevent duplicate export names in the same file, and export names are all considered within the global namespace of the file in question (they do not exist inside a particular module or scope within a source file). When using docify::embed!(..), duplicate results are simply embedded one after another, and this is by design.

If there are multiple items with the same inherent name in varipous scopes in the same file, and you want to export just one of them as a doc example, you should specify a unique ident as the export name for this item.

Note that if you wish to embed an entire file, you don’t need #[docify::export] at all and can instead specify just a path to docify::embed!(..) or docify::embed_run!(..).