Skip to content

custom parsing logic #13

@danieleades

Description

@danieleades

is it possible to 'map' or 'validate' a field using custom parsing logic?

My specific use case is to prepend a root directory to a provided PathBuf.

(The root directory should be provided by an environment variable and the compilation should fail if the environment variable is not present)

I guess what i'm looking for is something like darling's 'map' attribute.

#[derive(deluxe::ParseAttributes)]
pub struct DeriveAttributes {
    #[deluxe(map = parse_path)]
    path: PathBuf,
}

fn parse_path(s: String) -> Result<PathBuf, SomeError> {
    let prefix = Path::new(std::env::var("SOME_ARG").map_err(|_| SomeError)?);
    prefix.join(s)
}

(or something)

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