Enum serde_test::Token[][src]

pub enum Token {
Show variants Bool(bool), I8(i8), I16(i16), I32(i32), I64(i64), U8(u8), U16(u16), U32(u32), U64(u64), F32(f32), F64(f64), Char(char), Str(&'static str), BorrowedStr(&'static str), String(&'static str), Bytes(&'static [u8]), BorrowedBytes(&'static [u8]), ByteBuf(&'static [u8]), None, Some, Unit, UnitStruct { name: &'static str, }, UnitVariant { name: &'static str, variant: &'static str, }, NewtypeStruct { name: &'static str, }, NewtypeVariant { name: &'static str, variant: &'static str, }, Seq { len: Option<usize>, }, SeqEnd, Tuple { len: usize, }, TupleEnd, TupleStruct { name: &'static str, len: usize, }, TupleStructEnd, TupleVariant { name: &'static str, variant: &'static str, len: usize, }, TupleVariantEnd, Map { len: Option<usize>, }, MapEnd, Struct { name: &'static str, len: usize, }, StructEnd, StructVariant { name: &'static str, variant: &'static str, len: usize, }, StructVariantEnd, Enum { name: &'static str, },
}

Variants

Bool(bool)
Expand description

A serialized bool.

assert_tokens(&true, &[Token::Bool(true)]);
I8(i8)
Expand description

A serialized i8.

assert_tokens(&0i8, &[Token::I8(0)]);
I16(i16)
Expand description

A serialized i16.

assert_tokens(&0i16, &[Token::I16(0)]);
I32(i32)
Expand description

A serialized i32.

assert_tokens(&0i32, &[Token::I32(0)]);
I64(i64)
Expand description

A serialized i64.

assert_tokens(&0i64, &[Token::I64(0)]);
U8(u8)
Expand description

A serialized u8.

assert_tokens(&0u8, &[Token::U8(0)]);
U16(u16)
Expand description

A serialized u16.

assert_tokens(&0u16, &[Token::U16(0)]);
U32(u32)
Expand description

A serialized u32.

assert_tokens(&0u32, &[Token::U32(0)]);
U64(u64)
Expand description

A serialized u64.

assert_tokens(&0u64, &[Token::U64(0)]);
F32(f32)
Expand description

A serialized f32.

assert_tokens(&0f32, &[Token::F32(0.0)]);
F64(f64)
Expand description

A serialized f64.

assert_tokens(&0f64, &[Token::F64(0.0)]);
Char(char)
Expand description

A serialized char.

assert_tokens(&'\n', &[Token::Char('\n')]);
Str(&'static str)
Expand description

A serialized str.

let s = String::from("transient");
assert_tokens(&s, &[Token::Str("transient")]);
BorrowedStr(&'static str)
Expand description

A borrowed str.

let s: &str = "borrowed";
assert_tokens(&s, &[Token::BorrowedStr("borrowed")]);
String(&'static str)
Expand description

A serialized String.

let s = String::from("owned");
assert_tokens(&s, &[Token::String("owned")]);
Expand description

A serialized [u8]

BorrowedBytes(&'static [u8])
Expand description

A borrowed [u8].

ByteBuf(&'static [u8])
Expand description

A serialized ByteBuf

None
Expand description

A serialized Option<T> containing none.

let opt = None::<char>;
assert_tokens(&opt, &[Token::None]);
Some
Expand description

The header to a serialized Option<T> containing some value.

The tokens of the value follow after this header.

let opt = Some('c');
assert_tokens(&opt, &[
    Token::Some,
    Token::Char('c'),
]);
Unit
Expand description

A serialized ().

assert_tokens(&(), &[Token::Unit]);
UnitStruct
Expand description

A serialized unit struct of the given name.

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct X;

assert_tokens(&X, &[Token::UnitStruct { name: "X" }]);
Show fields

Fields of UnitStruct

name: &'static str
UnitVariant
Expand description

A unit variant of an enum.

#[derive(Serialize, Deserialize, PartialEq, Debug)]
enum E {
    A,
}

let a = E::A;
assert_tokens(&a, &[Token::UnitVariant { name: "E", variant: "A" }]);
Show fields

Fields of UnitVariant

name: &'static strvariant: &'static str
NewtypeStruct
Expand description

The header to a serialized newtype struct of the given name.

After this header is the value contained in the newtype struct.

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct N(String);

let n = N("newtype".to_owned());
assert_tokens(&n, &[
    Token::NewtypeStruct { name: "N" },
    Token::String("newtype"),
]);
Show fields

Fields of NewtypeStruct

name: &'static str
NewtypeVariant
Expand description

The header to a newtype variant of an enum.

After this header is the value contained in the newtype variant.

#[derive(Serialize, Deserialize, PartialEq, Debug)]
enum E {
    B(u8),
}

let b = E::B(0);
assert_tokens(&b, &[
    Token::NewtypeVariant { name: "E", variant: "B" },
    Token::U8(0),
]);
Show fields

Fields of NewtypeVariant

name: &'static strvariant: &'static str
Seq
Expand description

The header to a sequence.

After this header are the elements of the sequence, followed by SeqEnd.

let vec = vec!['a', 'b', 'c'];
assert_tokens(&vec, &[
    Token::Seq { len: Some(3) },
    Token::Char('a'),
    Token::Char('b'),
    Token::Char('c'),
    Token::SeqEnd,
]);
Show fields

Fields of Seq

len: Option<usize>
SeqEnd
Expand description

An indicator of the end of a sequence.

Tuple
Expand description

The header to a tuple.

After this header are the elements of the tuple, followed by TupleEnd.

let tuple = ('a', 100);
assert_tokens(&tuple, &[
    Token::Tuple { len: 2 },
    Token::Char('a'),
    Token::I32(100),
    Token::TupleEnd,
]);
Show fields

Fields of Tuple

len: usize
TupleEnd
Expand description

An indicator of the end of a tuple.

TupleStruct
Expand description

The header to a tuple struct.

After this header are the fields of the tuple struct, followed by TupleStructEnd.

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct T(u8, u8);

let t = T(0, 0);
assert_tokens(&t, &[
    Token::TupleStruct { name: "T", len: 2 },
    Token::U8(0),
    Token::U8(0),
    Token::TupleStructEnd,
]);
Show fields

Fields of TupleStruct

name: &'static strlen: usize
TupleStructEnd
Expand description

An indicator of the end of a tuple struct.

TupleVariant
Expand description

The header to a tuple variant of an enum.

After this header are the fields of the tuple variant, followed by TupleVariantEnd.

#[derive(Serialize, Deserialize, PartialEq, Debug)]
enum E {
    C(u8, u8),
}

let c = E::C(0, 0);
assert_tokens(&c, &[
    Token::TupleVariant { name: "E", variant: "C", len: 2 },
    Token::U8(0),
    Token::U8(0),
    Token::TupleVariantEnd,
]);
Show fields

Fields of TupleVariant

name: &'static strvariant: &'static strlen: usize
TupleVariantEnd
Expand description

An indicator of the end of a tuple variant.

Map
Expand description

The header to a map.

After this header are the entries of the map, followed by MapEnd.

use std::collections::BTreeMap;

let mut map = BTreeMap::new();
map.insert('A', 65);
map.insert('Z', 90);

assert_tokens(&map, &[
    Token::Map { len: Some(2) },
    Token::Char('A'),
    Token::I32(65),
    Token::Char('Z'),
    Token::I32(90),
    Token::MapEnd,
]);
Show fields

Fields of Map

len: Option<usize>
MapEnd
Expand description

An indicator of the end of a map.

Struct
Expand description

The header of a struct.

After this header are the fields of the struct, followed by StructEnd.

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct S {
    a: u8,
    b: u8,
}

let s = S { a: 0, b: 0 };
assert_tokens(&s, &[
    Token::Struct { name: "S", len: 2 },
    Token::Str("a"),
    Token::U8(0),
    Token::Str("b"),
    Token::U8(0),
    Token::StructEnd,
]);
Show fields

Fields of Struct

name: &'static strlen: usize
StructEnd
Expand description

An indicator of the end of a struct.

StructVariant
Expand description

The header of a struct variant of an enum.

After this header are the fields of the struct variant, followed by StructVariantEnd.

#[derive(Serialize, Deserialize, PartialEq, Debug)]
enum E {
    D { d: u8 },
}

let d = E::D { d: 0 };
assert_tokens(&d, &[
    Token::StructVariant { name: "E", variant: "D", len: 1 },
    Token::Str("d"),
    Token::U8(0),
    Token::StructVariantEnd,
]);
Show fields

Fields of StructVariant

name: &'static strvariant: &'static strlen: usize
StructVariantEnd
Expand description

An indicator of the end of a struct variant.

Enum
Expand description

The header to an enum of the given name.

#[derive(Serialize, Deserialize, PartialEq, Debug)]
enum E {
    A,
    B(u8),
    C(u8, u8),
    D { d: u8 },
}

let a = E::A;
assert_tokens(&a, &[
    Token::Enum { name: "E" },
    Token::Str("A"),
    Token::Unit,
]);

let b = E::B(0);
assert_tokens(&b, &[
    Token::Enum { name: "E" },
    Token::Str("B"),
    Token::U8(0),
]);

let c = E::C(0, 0);
assert_tokens(&c, &[
    Token::Enum { name: "E" },
    Token::Str("C"),
    Token::Seq { len: Some(2) },
    Token::U8(0),
    Token::U8(0),
    Token::SeqEnd,
]);

let d = E::D { d: 0 };
assert_tokens(&d, &[
    Token::Enum { name: "E" },
    Token::Str("D"),
    Token::Map { len: Some(1) },
    Token::Str("d"),
    Token::U8(0),
    Token::MapEnd,
]);
Show fields

Fields of Enum

name: &'static str

Trait Implementations

impl Clone for Token[src]

fn clone(&self) -> Token[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Token[src]

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

Formats the value using the given formatter. Read more

impl Display for Token[src]

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl PartialEq<Token> for Token[src]

fn eq(&self, other: &Token) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Token) -> bool[src]

This method tests for !=.

impl Copy for Token[src]

impl StructuralPartialEq for Token[src]

Auto Trait Implementations

impl RefUnwindSafe for Token

impl Send for Token

impl Sync for Token

impl Unpin for Token

impl UnwindSafe for Token

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.