use yog_data::Shape;
use super::model::Type;
impl Type {
pub(crate) fn of_shape(shape: &Shape) -> Type {
match shape {
Shape::Bool => Type::Bool,
Shape::Int { min, max } => {
if *min >= i64::from(i32::MIN) && *max <= i64::from(i32::MAX) {
Type::I32
} else {
Type::I64
}
}
Shape::Float { bits } if *bits <= u32::BITS => Type::F32,
Shape::Float { .. } => Type::F64,
Shape::Str | Shape::Atom => Type::String,
Shape::Text => Type::Text,
Shape::Ref([kind]) => Type::Content((*kind).to_string()),
Shape::Tag(_) => Type::Tag,
Shape::List(inner) => Type::List(Box::new(Type::of_shape(&inner()))),
Shape::Map(inner) => {
Type::Map(Box::new(Type::String), Box::new(Type::of_shape(&inner())))
}
Shape::Optional(inner) => Type::of_shape(&inner()).nullable(),
Shape::Struct(s) => Type::Yog(s.name.to_string()),
Shape::Enum(e) => Type::Yog(e.name.to_string()),
_ => Type::Unknown,
}
}
}