pub( crate ) mod private
{
use crate::exposed::*;
use crate::type_rightmost;
#[derive( Debug, PartialEq, Copy, Clone )]
pub enum ContainerKind
{
No,
Vector,
HashMap,
HashSet,
}
pub fn type_container_kind( ty : &syn::Type ) -> ContainerKind
{
if let syn::Type::Path( path ) = ty
{
let last = &path.path.segments.last();
if last.is_none()
{
return ContainerKind::No
}
match last.unwrap().ident.to_string().as_ref()
{
"Vec" => { return ContainerKind::Vector }
"HashMap" => { return ContainerKind::HashMap }
"HashSet" => { return ContainerKind::HashSet }
_ => { return ContainerKind::No }
}
}
ContainerKind::No
}
pub fn type_optional_container_kind( ty : &syn::Type ) -> ( ContainerKind, bool )
{
if type_rightmost( ty ) == Some( "Option".to_string() )
{
let ty2 = type_parameters( ty, 0 ..= 0 ).first().map( | e | *e );
if ty2.is_none()
{
return ( ContainerKind::No, false )
}
let ty2 = ty2.unwrap();
return ( type_container_kind( ty2 ), true );
}
return ( type_container_kind( ty ), false );
}
}
#[ doc( inline ) ]
pub use exposed::*;
pub mod exposed
{
#[ doc( inline ) ]
pub use super::prelude::*;
#[ doc( inline ) ]
pub use super::private::
{
ContainerKind,
type_container_kind,
type_optional_container_kind,
};
}
pub mod prelude
{
}