mirror of
https://github.com/urbit/ares.git
synced 2024-11-26 09:57:56 +03:00
Move u64/u128 to IndirectAtom as well
This commit is contained in:
parent
7debba4ad7
commit
1ae6303cbf
@ -464,6 +464,24 @@ impl IndirectAtom {
|
||||
UBig::from_le_bytes_stack(stack, self.as_bytes())
|
||||
}
|
||||
|
||||
pub unsafe fn as_u64(self) -> Result<u64> {
|
||||
if self.size() == 1 {
|
||||
Ok(*(self.data_pointer()))
|
||||
} else {
|
||||
Err(Error::NotRepresentable)
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn as_u128_pair(self) -> Result<[u64; 2]> {
|
||||
if self.size() <= 2 {
|
||||
let mut u128_array = &mut [0u64; 2];
|
||||
u128_array.copy_from_slice(&(self.as_slice()[0..2]));
|
||||
Ok(unsafe { *u128_array })
|
||||
} else {
|
||||
Err(Error::NotRepresentable)
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure that the size does not contain any trailing 0 words */
|
||||
pub unsafe fn normalize(&mut self) -> &Self {
|
||||
let mut index = self.size() - 1;
|
||||
@ -826,24 +844,6 @@ impl Atom {
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn as_u64(self) -> Result<u64> {
|
||||
if self.size() == 1 {
|
||||
Ok(*(self.data_pointer()))
|
||||
} else {
|
||||
Err(Error::NotRepresentable)
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn as_u128_pair(self) -> Result<[u64; 2]> {
|
||||
if self.size() <= 2 {
|
||||
let mut u128_array = &mut [0u64; 2];
|
||||
u128_array.copy_from_slice(&(self.as_slice()[0..2]));
|
||||
Ok(unsafe { *u128_array })
|
||||
} else {
|
||||
Err(Error::NotRepresentable)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_noun(self) -> Noun {
|
||||
Noun { atom: self }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user