coercion the easy cases

main
Ziyang Hu 2 years ago
parent 98156906e7
commit 1ddfbef091

@ -107,9 +107,7 @@ impl Typing {
_ => unreachable!()
})
}
pub fn is_nullable(&self) -> bool {
matches!(self, Typing::Any | Typing::Nullable(_))
}
pub fn coerce<'a>(&self, v: Value<'a>) -> Result<Value<'a>> {
if *self == Typing::Any {
return Ok(v);
@ -127,8 +125,6 @@ impl Typing {
}
match self {
Typing::Any => unreachable!(),
Typing::Nullable(_) => unreachable!(),
Typing::Bool => self.coerce_bool(v),
Typing::Int => self.coerce_int(v),
Typing::Float => self.coerce_float(v),
@ -148,6 +144,9 @@ impl Typing {
Typing::NamedTuple(nt) => {
todo!()
}
Typing::Any => unreachable!(),
Typing::Nullable(_) => unreachable!(),
}
}
fn coerce_bool<'a>(&self, v: Value<'a>) -> Result<Value<'a>> {

Loading…
Cancel
Save