noun: add as_u64() method for Atom and IndirectAtom

This commit is contained in:
Edward Amsden 2023-09-24 00:05:45 -05:00
parent 4dd009c04c
commit 71ab3c8ef9

View File

@ -431,6 +431,14 @@ impl IndirectAtom {
}
}
pub unsafe fn as_u64(self) -> Result<u64> {
if self.size() == 1 {
Ok(*(self.data_pointer()))
} else {
Err(Error::NotRepresentable)
}
}
pub fn as_atom(self) -> Atom {
Atom { indirect: self }
}
@ -630,6 +638,16 @@ impl Atom {
unsafe { is_indirect_atom(self.raw) }
}
pub fn as_u64(self) -> Result<u64> {
if self.is_direct() {
Ok(unsafe { self.direct.data() })
} else {
unsafe {
self.indirect.as_u64()
}
}
}
pub fn as_direct(&self) -> Result<DirectAtom> {
if self.is_direct() {
unsafe { Ok(self.direct) }