fn list_value_from_json(
    val: &JsonValue,
    max_count: &u32,
    nested_type: &ConfigNestedValueType,
) -> Result<ListValue, FieldError> {
    // define our array up here so its identifier is available for our helper macro
    let array = val.as_array().ok_or_else(|| FieldError::JsonTypeMismatch {
        expected: JsonTy::Array,
        received: val.ty(),
    })?;
    let max = *max_count as usize;
    if array.len() > max {
        return Err(FieldError::VectorTooLong { max, actual: array.len() });
    }

    /// Build a ListValue out of all the array elements.
    ///
    /// A macro because enum variants don't exist at the type level in Rust at time of writing.
    macro_rules! list_from_array {
        ($list_variant:ident, $val:ident => $convert:expr) => {{
            let mut list = vec![];
            for $val in array {
                list.push($convert);
            }
            ListValue::$list_variant(list)
        }};
    }

    Ok(match nested_type {
        ConfigNestedValueType::Bool => {
            list_from_array!(FlagList, v => v.parse_bool()?)
        }
        ConfigNestedValueType::Uint8 => list_from_array!(Unsigned8List, v => v.parse_u8()?),
        ConfigNestedValueType::Uint16 => {
            list_from_array!(Unsigned16List, v => v.parse_u16()?)
        }
        ConfigNestedValueType::Uint32 => {
            list_from_array!(Unsigned32List, v => v.parse_u32()?)
        }
        ConfigNestedValueType::Uint64 => {
            list_from_array!(Unsigned64List, v => v.parse_u64()?)
        }
        ConfigNestedValueType::Int8 => list_from_array!(Signed8List,  v => v.parse_i8()?),
        ConfigNestedValueType::Int16 => list_from_array!(Signed16List, v => v.parse_i16()?),
        ConfigNestedValueType::Int32 => list_from_array!(Signed32List, v => v.parse_i32()?),
        ConfigNestedValueType::Int64 => list_from_array!(Signed64List, v => v.parse_i64()?),
        ConfigNestedValueType::String { max_size } => {
            list_from_array!(TextList, v => v.parse_string(*max_size)?)
        }
    })
}
/// Parse `val` as a list/vector of configuration values.
Parse `val` as a list/vector of configuration values.
Parse ` val ` as a list / vector of configuration values .
fn list_value_from_json(
    val: &JsonValue,
    max_count: &u32,
    nested_type: &ConfigNestedValueType,
) -> Result<ListValue, FieldError> {
    // define our array up here so its identifier is available for our helper macro
    let array = val.as_array().ok_or_else(|| FieldError::JsonTypeMismatch {
        expected: JsonTy::Array,
        received: val.ty(),
    })?;
    let max = *max_count as usize;
    if array.len() > max {
        return Err(FieldError::VectorTooLong { max, actual: array.len() });
    }
    /// Build a ListValue out of all the array elements.
    ///
    /// A macro because enum variants don't exist at the type level in Rust at time of writing.
    macro_rules! list_from_array {
        ($list_variant:ident, $val:ident => $convert:expr) => {{
            let mut list = vec![];
            for $val in array {
                list.push($convert);
            }
            ListValue::$list_variant(list)
        }};
    }
    Ok(match nested_type {
        ConfigNestedValueType::Bool => {
            list_from_array!(FlagList, v => v.parse_bool()?)
        }
        ConfigNestedValueType::Uint8 => list_from_array!(Unsigned8List, v => v.parse_u8()?),
        ConfigNestedValueType::Uint16 => {
            list_from_array!(Unsigned16List, v => v.parse_u16()?)
        }
        ConfigNestedValueType::Uint32 => {
            list_from_array!(Unsigned32List, v => v.parse_u32()?)
        }
        ConfigNestedValueType::Uint64 => {
            list_from_array!(Unsigned64List, v => v.parse_u64()?)
        }
        ConfigNestedValueType::Int8 => list_from_array!(Signed8List,  v => v.parse_i8()?),
        ConfigNestedValueType::Int16 => list_from_array!(Signed16List, v => v.parse_i16()?),
        ConfigNestedValueType::Int32 => list_from_array!(Signed32List, v => v.parse_i32()?),
        ConfigNestedValueType::Int64 => list_from_array!(Signed64List, v => v.parse_i64()?),
        ConfigNestedValueType::String { max_size } => {
            list_from_array!(TextList, v => v.parse_string(*max_size)?)
        }
    })
}
fn list_value_from_json ( val : & JsonValue , max_count : & u32 , nested_type : & ConfigNestedValueType , ) -> Result < ListValue , FieldError > { // define our array up here so its identifier is available for our helper macro let array = val . as_array ( ) . ok_or_else ( | | FieldError :: JsonTypeMismatch { expected : JsonTy :: Array , received : val . ty ( ) , } ) ? ; let max = * max_count as usize ; if array . len ( ) > max { return Err ( FieldError :: VectorTooLong { max , actual : array . len ( ) } ) ; } /// Build a ListValue out of all the array elements. /// /// A macro because enum variants don't exist at the type level in Rust at time of writing. macro_rules! list_from_array { ( $list_variant : ident $val : ident $convert : expr ) => { { let mut list vec [ ] for $val in array { list push ( $convert ) } ListValue $list_variant ( list ) } } ; } Ok ( match nested_type { ConfigNestedValueType :: Bool => { list_from_array ! ( FlagList v v parse_bool ( ) ) } ConfigNestedValueType :: Uint8 => list_from_array ! ( Unsigned8List v v parse_u8 ( ) ) , ConfigNestedValueType :: Uint16 => { list_from_array ! ( Unsigned16List v v parse_u16 ( ) ) } ConfigNestedValueType :: Uint32 => { list_from_array ! ( Unsigned32List v v parse_u32 ( ) ) } ConfigNestedValueType :: Uint64 => { list_from_array ! ( Unsigned64List v v parse_u64 ( ) ) } ConfigNestedValueType :: Int8 => list_from_array ! ( Signed8List v v parse_i8 ( ) ) , ConfigNestedValueType :: Int16 => list_from_array ! ( Signed16List v v parse_i16 ( ) ) , ConfigNestedValueType :: Int32 => list_from_array ! ( Signed32List v v parse_i32 ( ) ) , ConfigNestedValueType :: Int64 => list_from_array ! ( Signed64List v v parse_i64 ( ) ) , ConfigNestedValueType :: String { max_size } => { list_from_array ! ( TextList v v parse_string ( max_size ) ) } } ) }
Parse `val` as a list/vector of configuration values.
Parse ` val ` as a list / vector of configuration values .
val
&JsonValue
max_count
&u32
nested_type
&ConfigNestedValueType
val
&JsonValue
max_count
&u32
nested_type
&ConfigNestedValueType