Extract can/ into its own crate, plus its deps

This commit is contained in:
Richard Feldman 2020-03-05 20:58:12 -05:00
parent 97e6affa88
commit 3b6ed43126
62 changed files with 910 additions and 418 deletions

View file

@ -0,0 +1,66 @@
use crate::pattern::Pattern;
use roc_region::all::{Located, Region};
use roc_types::types::{AnnotationSource, PReason, Reason};
#[derive(Debug, Clone, PartialEq)]
pub enum Expected<T> {
NoExpectation(T),
FromAnnotation(Located<Pattern>, usize, AnnotationSource, T),
ForReason(Reason, T, Region),
}
/// Like Expected, but for Patterns.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PExpected<T> {
NoExpectation(T),
ForReason(PReason, T, Region),
}
impl<T> PExpected<T> {
pub fn get_type(self) -> T {
match self {
PExpected::NoExpectation(val) => val,
PExpected::ForReason(_, val, _) => val,
}
}
pub fn get_type_ref(&self) -> &T {
match self {
PExpected::NoExpectation(val) => val,
PExpected::ForReason(_, val, _) => val,
}
}
pub fn get_type_mut_ref(&mut self) -> &mut T {
match self {
PExpected::NoExpectation(val) => val,
PExpected::ForReason(_, val, _) => val,
}
}
}
impl<T> Expected<T> {
pub fn get_type(self) -> T {
match self {
Expected::NoExpectation(val) => val,
Expected::ForReason(_, val, _) => val,
Expected::FromAnnotation(_, _, _, val) => val,
}
}
pub fn get_type_ref(&self) -> &T {
match self {
Expected::NoExpectation(val) => val,
Expected::ForReason(_, val, _) => val,
Expected::FromAnnotation(_, _, _, val) => val,
}
}
pub fn get_type_mut_ref(&mut self) -> &mut T {
match self {
Expected::NoExpectation(val) => val,
Expected::ForReason(_, val, _) => val,
Expected::FromAnnotation(_, _, _, val) => val,
}
}
}