mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
add impl RocRefcounted for RocResult
This commit is contained in:
parent
0284248320
commit
45cca34c12
1 changed files with 26 additions and 0 deletions
|
@ -214,6 +214,32 @@ impl<T, E> RocResult<T, E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T, E> RocRefcounted for RocResult<T, E>
|
||||||
|
where
|
||||||
|
T: RocRefcounted,
|
||||||
|
E: RocRefcounted,
|
||||||
|
{
|
||||||
|
fn inc(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
match self.tag {
|
||||||
|
RocResultTag::RocOk => (*self.payload.ok).inc(),
|
||||||
|
RocResultTag::RocErr => (*self.payload.err).inc(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn dec(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
match self.tag {
|
||||||
|
RocResultTag::RocOk => (*self.payload.ok).dec(),
|
||||||
|
RocResultTag::RocErr => (*self.payload.err).dec(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn is_refcounted() -> bool {
|
||||||
|
T::is_refcounted() || E::is_refcounted()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T, E> From<RocResult<T, E>> for Result<T, E> {
|
impl<T, E> From<RocResult<T, E>> for Result<T, E> {
|
||||||
fn from(roc_result: RocResult<T, E>) -> Self {
|
fn from(roc_result: RocResult<T, E>) -> Self {
|
||||||
use RocResultTag::*;
|
use RocResultTag::*;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue