Skip to content

How to handle heterogeneous optional fields #542

Answered by VorpalBlade
VorpalBlade asked this question in Q&A
Discussion options

You must be logged in to vote

This seems to work:

fn flattener<T>(e: Option<(&str, Option<T>)>) -> Option<T> {
    e.map(|(_, arg)| arg).flatten()
}

fn directive(i: &mut &str) -> PResult<Directive> {
    let entry_type = any_string.context(StrContext::Label("entry type"));
    let path = any_string.context(StrContext::Label("path"));
    let mode = mode_parser.context(StrContext::Label("mode"));
    let user = id_parser.context(StrContext::Label("user"));
    let group = id_parser.context(StrContext::Label("group"));
    let age = optional_string.context(StrContext::Label("age"));
    let argument = optional_string.context(StrContext::Label("argument"));

    let mut parser = (
        entry_type,
        space1,

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@VorpalBlade
Comment options

@VorpalBlade
Comment options

Answer selected by VorpalBlade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants