Skip to content

Commit

Permalink
Merge pull request #6905 from roc-lang/rocresult-refcount
Browse files Browse the repository at this point in the history
Add impl RocRefcounted for RocResult
  • Loading branch information
lukewilliamboswell committed Jul 15, 2024
2 parents 7a288dd + 45cca34 commit 5cf4a4a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions crates/roc_std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
fn from(roc_result: RocResult<T, E>) -> Self {
use RocResultTag::*;
Expand Down

0 comments on commit 5cf4a4a

Please sign in to comment.