mirror of
https://github.com/urbit/ares.git
synced 2024-11-22 06:32:47 +03:00
noun: add as_u64() method for Atom and IndirectAtom
This commit is contained in:
parent
4dd009c04c
commit
71ab3c8ef9
@ -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) }
|
||||
|
Loading…
Reference in New Issue
Block a user