Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Library to inline out-of-line mod items and resolve #[path = "..."] #6

@dtolnay

Description

@dtolnay

In dtolnay/cargo-expand#11 I need to be able to take a source file as a syn::File and transitively expand every mod m; into mod m { ... } with its contents drawn from the right file.

Concretely we'll be replacing the content field of every ItemMod with Some if it is None.

Example input:

src/lib.rs

#[cfg(feature = "m1")]
mod m1;

#[cfg_attr(feature = "m2", path = "m2.rs")]
#[cfg_attr(not(feature = "m2"), path = "empty.rs")]
mod placeholder;

src/m1.rs

struct M1;

src/m2.rs

//! module level doc comment

struct M2;

src/empty.rs

// empty file

The result will look like:

#[cfg(feature = "m1")]
mod m1 {
    struct M1;
}

#[cfg(feature = "m2")]
mod placeholder {
    //! module level doc comment

    struct M2;
}

#[cfg(not(feature = "m2"))]
mod placeholder {
}

Possible API:

pub fn parse_and_inline_modules(root: &std::path::Path) -> syn::File;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions