Enum jomini::binary::Token

source ·
pub enum Token<'a> {
Show 14 variants Open, Close, Equal, U32(u32), U64(u64), I32(i32), Bool(bool), Quoted(Scalar<'a>), Unquoted(Scalar<'a>), F32([u8; 4]), F64([u8; 8]), Rgb(Rgb), I64(i64), Id(u16),
}
Expand description

Binary token, the raw form of BinaryToken

This binary token contains the yielded raw tokens, and won’t match open and close tokens together, nor does it make a determination if open and close represents an array, object, or both.

Variants§

§

Open

‘{’

§

Close

‘}’

§

Equal

‘=’

§

U32(u32)

32bit unsigned integer

§

U64(u64)

64bit unsigned integer

§

I32(i32)

32bit signed integer

§

Bool(bool)

boolean

§

Quoted(Scalar<'a>)

quoted text

§

Unquoted(Scalar<'a>)

text that is not quoted

§

F32([u8; 4])

32bits of floating point data

§

F64([u8; 8])

64bits of floating point data

§

Rgb(Rgb)

Rgb data

§

I64(i64)

64bit signed integer

§

Id(u16)

token id that can be resolved to a string via a TokenResolver

Implementations§

source§

impl<'a> Token<'a>

source

pub fn write(&self, wtr: impl Write) -> Result<(), Error>

Write the binary representation of a token to a writer

use jomini::binary::Token;
let out = Vec::new();
let mut cursor = std::io::Cursor::new(out);
for token in &[Token::Id(0x00e1), Token::Equal, Token::U32(10)] {
    token.write(&mut cursor)?;
}

assert_eq!(&cursor.into_inner(), &[0xe1, 0x00, 0x01, 0x00, 0x14, 0x00, 0x0a, 0x00, 0x00, 0x00]);

Trait Implementations§

source§

impl<'a> Clone for Token<'a>

source§

fn clone(&self) -> Token<'a>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Token<'a>

source§

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

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

impl<'a> PartialEq for Token<'a>

source§

fn eq(&self, other: &Token<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Copy for Token<'a>

source§

impl<'a> Eq for Token<'a>

source§

impl<'a> StructuralPartialEq for Token<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Token<'a>

§

impl<'a> RefUnwindSafe for Token<'a>

§

impl<'a> Send for Token<'a>

§

impl<'a> Sync for Token<'a>

§

impl<'a> Unpin for Token<'a>

§

impl<'a> UnwindSafe for Token<'a>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T> ToOwned for T
where T: Clone,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.