Skip to main content

Atom

Struct Atom 

Source
pub struct Atom { /* private fields */ }
Expand description

An arbitrarily large unsigned integer.

An atom is an arbitrarily large unsigned integer represented as a little-endian contiguous sequence of bytes. An atom can be:

  • created a single bit at a time or from other types that can be easily converted into atoms like primitive unsigned integers, strings, and string slices;
  • iterated over a single bit at a time;
  • compared to other atoms and other atom-like types;
  • pretty-printed as a hexadecimal number;
  • converted into a noun, a primitive unsigned integer type, or a string slice.

§Examples

To create a new atom, use one of the From<T> implementations:

let atom = Atom::from("hello");
assert_eq!(atom, "hello");
let atom = Atom::from(0u8);
assert_eq!(atom, 0u8);

Implementations§

Source§

impl Atom

Source

pub fn builder() -> Builder

Creates an empty atom builder.

This method is equivalent to Builder::new().

Source

pub const fn null() -> Self

Creates the atom 0.

Source

pub const fn is_null(&self) -> bool

Returns true if this atom is null (i.e. the atom 0).

Source

pub const fn bit_len(&self) -> usize

Returns the length in bits of this atom.

Source

pub fn hash(&self) -> u64

Computes the hash of this atom.

Source

pub fn as_bytes(&self) -> &[u8]

Converts this atom into a byte slice.

Source

pub fn as_str(&self) -> Result<&str, Utf8Error>

Converts this atom into a string slice, returning an error if the atom is not composed of valid UTF-8 bytes.

Source

pub fn as_u8(&self) -> Option<u8>

Converts this atom into an 8-bit unsigned integer, returning None if the atom is greater than u8::MAX.

§Examples
let uint = u8::MAX;
let atom = Atom::from(uint);
assert_eq!(atom.as_u8().unwrap(), uint);
Source

pub fn as_u16(&self) -> Option<u16>

Converts this atom into an 16-bit unsigned integer, returning None if the atom is greater than u16::MAX.

§Examples
let uint = u16::MAX;
let atom = Atom::from(uint);
assert_eq!(atom.as_u16().unwrap(), uint);
Source

pub fn as_u32(&self) -> Option<u32>

Converts this atom into an 32-bit unsigned integer, returning None if the atom is greater than u32::MAX.

§Examples
let uint = u32::MAX;
let atom = Atom::from(uint);
assert_eq!(atom.as_u32().unwrap(), uint);
Source

pub fn as_u64(&self) -> Option<u64>

Converts this atom into an 64-bit unsigned integer, returning None if the atom is greater than u64::MAX.

§Examples
let uint = u64::MAX;
let atom = Atom::from(uint);
assert_eq!(atom.as_u64().unwrap(), uint);
Source

pub fn as_u128(&self) -> Option<u128>

Converts this atom into an 128-bit unsigned integer, returning None if the atom is greater than u128::MAX.

§Examples
let uint = u128::MAX;
let atom = Atom::from(uint);
assert_eq!(atom.as_u128().unwrap(), uint);
Source

pub fn as_usize(&self) -> Option<usize>

Converts this atom into a pointer-sized unsigned integer, returning None if the atom is greater than usize::MAX.

§Examples
let uint = usize::MAX;
let atom = Atom::from(uint);
assert_eq!(atom.as_usize().unwrap(), uint);
Source

pub fn to_vec(&self) -> Vec<u8>

Copies this atom into a byte vector.

Source

pub fn into_vec(self) -> Vec<u8>

Converts this atom into a byte vector, consuming the atom.

This method does not allocate on the heap.

Source

pub fn as_noun(&self) -> Noun

Source

pub fn into_noun(self) -> Noun

Source

pub fn iter(&self) -> Iter<'_>

Returns a bitwise iterator over this atom.

Source

pub fn as_big(&self) -> UBig

Returns the atom as a big integer

Source

pub fn format_aura(&self, aura: Aura) -> Result<String, FormatError>

Formats an atom into a string using the given aura

§Examples
let atom = Atom::from(123434910u64);
let s = atom.format_aura(Aura::U).unwrap();
assert_eq!(s, "123.434.910");
Source

pub fn parse_aura(aura: Aura, s: &str) -> Result<Self, ParseError>

Parses a string into an atom using the given aura

§Examples
let atom = Atom::parse_aura(Aura::U, "123.434.910").unwrap();
assert_eq!(atom, Atom::from(123434910u64));

Trait Implementations§

Source§

impl Clone for Atom

Source§

fn clone(&self) -> Atom

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Atom

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Atom

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<&str> for Atom

Source§

fn from(string: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Atom> for Noun

Source§

fn from(atom: Atom) -> Self

Converts to this type from the input type.
Source§

impl From<Atom> for Rc<Noun>

Source§

fn from(atom: Atom) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Atom

Source§

fn from(string: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Atom

Source§

fn from(vec: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Atom

Source§

fn from(uint: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Atom

Source§

fn from(uint: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Atom

Source§

fn from(uint: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Atom

Source§

fn from(uint: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Atom

Source§

fn from(uint: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Atom

Source§

fn from(uint: usize) -> Self

Converts to this type from the input type.
Source§

impl Hash for Atom

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq<&Atom> for Atom

Source§

fn eq(&self, other: &&Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&str> for Atom

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for Atom

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<u128> for Atom

Source§

fn eq(&self, other: &u128) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<u16> for Atom

Source§

fn eq(&self, other: &u16) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<u32> for Atom

Source§

fn eq(&self, other: &u32) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<u64> for Atom

Source§

fn eq(&self, other: &u64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<u8> for Atom

Source§

fn eq(&self, other: &u8) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<usize> for Atom

Source§

fn eq(&self, other: &usize) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Atom

Source§

fn eq(&self, other: &Atom) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&OsStr> for Atom

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(string: &OsStr) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Atomish for &Atom

Source§

impl Atomish for Atom

Source§

impl Atomish for Box<Atom>

Source§

impl Eq for Atom

Source§

impl Nounish for &Atom

Source§

impl Nounish for Atom

Source§

impl Nounish for Box<Atom>

Source§

impl StructuralPartialEq for Atom

Auto Trait Implementations§

§

impl Freeze for Atom

§

impl RefUnwindSafe for Atom

§

impl Send for Atom

§

impl Sync for Atom

§

impl Unpin for Atom

§

impl UnsafeUnpin for Atom

§

impl UnwindSafe for Atom

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<I, T> ExtractContext<I, ()> for T

Source§

fn extract_context(self, _original_input: I)

Given the context attached to a nom error, and given the original input to the nom parser, extract more the useful context information. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Indentable for T
where T: Display,

Source§

fn indented(self, indent: &str) -> Indented<'_, Self>

Wrap this object so that its Display representation is indented with the given indent. Each non-empty line of the formatted output will be prefixed with the indent. Read more
Source§

fn indented_skip_initial(self, indent: &str) -> IndentedSkipIntial<'_, Self>

Wrap this object so that its Display representation is indented with the given indent. Each non-empty line except for the first of the formatted output will be prefixed with the indent. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<I> RecreateContext<I> for I

Source§

fn recreate_context(_original_input: I, tail: I) -> I

Given the original input, as well as the context reported by nom, recreate a context in the original string where the error occurred. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.