fn extract_bits<'de, A, T, S>(
    mut seq: A,
    names: &[S],
    is_human_readable: bool,
) -> Result<T, A::Error>
where
    A: SeqAccess<'de>,
    T: OptionSet,
    S: Deref<Target = str>,
{
    use serde::de::Error;

    let mut flags = T::default();

    let max_elements = if !is_human_readable {
        // For non-human-readable formats, the first element will contain the number of elements
        seq.next_element::<usize>()?.unwrap()
    } else {
        usize::MAX
    };

    let mut count = 0;
    loop {
        if count >= max_elements {
            break;
        }

        let elem = seq.next_element::<Str<'de>>()?;
        if elem.is_none() {
            break;
        }

        let elem = elem.unwrap();
        let mut iter = T::VARIANTS.iter().zip(names);

        match iter.find(|&(_, name)| **name == *elem) {
            Some((&flag, _)) => flags |= flag,
            None => return Err(A::Error::unknown_variant(&elem, T::NAMES)),
        }

        count += 1;
    }

    Ok(flags)
}
/// Actually performs the sequence processing and flag extraction.
Actually performs the sequence processing and flag extraction.
Actually performs the sequence processing and flag extraction .
fn extract_bits<'de, A, T, S>(
    mut seq: A,
    names: &[S],
    is_human_readable: bool,
) -> Result<T, A::Error>
where
    A: SeqAccess<'de>,
    T: OptionSet,
    S: Deref<Target = str>,
{
    use serde::de::Error;
    let mut flags = T::default();
    let max_elements = if !is_human_readable {
        // For non-human-readable formats, the first element will contain the number of elements
        seq.next_element::<usize>()?.unwrap()
    } else {
        usize::MAX
    };
    let mut count = 0;
    loop {
        if count >= max_elements {
            break;
        }
        let elem = seq.next_element::<Str<'de>>()?;
        if elem.is_none() {
            break;
        }
        let elem = elem.unwrap();
        let mut iter = T::VARIANTS.iter().zip(names);
        match iter.find(|&(_, name)| **name == *elem) {
            Some((&flag, _)) => flags |= flag,
            None => return Err(A::Error::unknown_variant(&elem, T::NAMES)),
        }
        count += 1;
    }
    Ok(flags)
}
fn extract_bits < ' de , A , T , S > ( mut seq : A , names : & [ S ] , is_human_readable : bool , ) -> Result < T , A :: Error > where A : SeqAccess < ' de > , T : OptionSet , S : Deref < Target = str > , { use serde :: de :: Error ; let mut flags = T :: default ( ) ; let max_elements = if ! is_human_readable { // For non-human-readable formats, the first element will contain the number of elements seq . next_element :: < usize > ( ) ? . unwrap ( ) } else { usize :: MAX } ; let mut count = 0 ; loop { if count >= max_elements { break ; } let elem = seq . next_element :: < Str < ' de > > ( ) ? ; if elem . is_none ( ) { break ; } let elem = elem . unwrap ( ) ; let mut iter = T :: VARIANTS . iter ( ) . zip ( names ) ; match iter . find ( | & ( _ , name ) | * * name == * elem ) { Some ( ( & flag , _ ) ) => flags |= flag , None => return Err ( A :: Error :: unknown_variant ( & elem , T :: NAMES ) ) , } count += 1 ; } Ok ( flags ) }
Actually performs the sequence processing and flag extraction.
Actually performs the sequence processing and flag extraction .
seq
A
names
&[S]
is_human_readable
bool
seq
A
names
&[S]
is_human_readable
bool