add impl RocRefcounted for RocResult

This commit is contained in:
Luke Boswell 2024-07-15 14:33:19 +10:00
parent 0284248320
commit 45cca34c12
No known key found for this signature in database
GPG Key ID: F6DB3C9DB47377B0

View File

@ -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::*;