Function macro_tools::protected::container_kind::of_optional

source ·
pub fn of_optional(ty: &Type) -> (ContainerKind, bool)
Expand description

Return kind of container specified by type. Unlike of_type it also understand optional types.

Good to verify Option< alloc::vec::Vec< i32 > > is optional vector.

§Basic use-case.

use macro_tools::exposed::*;

let code = qt!( Option< std::collections::HashMap< i32, i32 > > );
let tree_type = syn::parse2::< syn::Type >( code ).unwrap();
let ( kind, optional ) = container_kind::of_optional( &tree_type );
assert_eq!( kind, container_kind::ContainerKind::HashMap );
assert_eq!( optional, true );