mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Extract can/ into its own crate, plus its deps
This commit is contained in:
parent
97e6affa88
commit
3b6ed43126
62 changed files with 910 additions and 418 deletions
66
compiler/can/src/expected.rs
Normal file
66
compiler/can/src/expected.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue