Emplace variables made from types in expectations

This commit is contained in:
Ayaz Hafiz 2022-10-24 13:11:35 -05:00
parent 04a3f1c00e
commit 9b24205906
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 56 additions and 34 deletions

View file

@ -38,6 +38,16 @@ impl<T> PExpected<T> {
}
}
#[inline(always)]
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> PExpected<U> {
match self {
PExpected::NoExpectation(val) => PExpected::NoExpectation(f(val)),
PExpected::ForReason(reason, val, region) => {
PExpected::ForReason(reason, f(val), region)
}
}
}
pub fn replace<U>(self, new: U) -> PExpected<U> {
match self {
PExpected::NoExpectation(_val) => PExpected::NoExpectation(new),
@ -89,6 +99,17 @@ impl<T> Expected<T> {
}
}
#[inline(always)]
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Expected<U> {
match self {
Expected::NoExpectation(val) => Expected::NoExpectation(f(val)),
Expected::ForReason(reason, val, region) => Expected::ForReason(reason, f(val), region),
Expected::FromAnnotation(pattern, size, source, val) => {
Expected::FromAnnotation(pattern, size, source, f(val))
}
}
}
pub fn replace<U>(self, new: U) -> Expected<U> {
match self {
Expected::NoExpectation(_val) => Expected::NoExpectation(new),