Skip to main content

ValueReader

Struct ValueReader 

Source
pub struct ValueReader<'c, 'r, 'b> { /* private fields */ }
Expand description

Reads values at their types from bytes, within limits: the runtime’s own values (read_value), and a Rust value its Shaped mapping reads part by part, with no runtime value between.

Implementations§

Source§

impl<'b> ValueReader<'_, '_, 'b>

Source

pub fn catalog(&self) -> &Catalog

The catalog the types read at are in.

Source

pub fn mismatch(&self, ty: &Type) -> DecodeError

The refusal of a value read at ty, a type the Rust type does not map to, or a value of it that is none of the Rust type’s.

Source

pub fn unit(&mut self, ty: &Type) -> Result<(), DecodeError>

Reads Unit at ty.

§Errors

When ty is not Unit; so for every reader below and its type, and for bytes that are not a value of it within the limits.

Source

pub fn bool(&mut self, ty: &Type) -> Result<bool, DecodeError>

Reads a Bool.

§Errors

As ValueReader::unit.

Source

pub fn int(&mut self, ty: &Type) -> Result<Int, DecodeError>

Reads an Int.

§Errors

As ValueReader::unit.

Source

pub fn decimal(&mut self, ty: &Type) -> Result<Decimal, DecodeError>

Reads a Decimal.

§Errors

As ValueReader::unit.

Source

pub fn duration(&mut self, ty: &Type) -> Result<Duration, DecodeError>

Reads a Duration.

§Errors

As ValueReader::unit.

Source

pub fn instant(&mut self, ty: &Type) -> Result<Instant, DecodeError>

Reads an Instant.

§Errors

As ValueReader::unit.

Source

pub fn text(&mut self, ty: &Type) -> Result<&'b str, DecodeError>

Reads a Text.

§Errors

As ValueReader::unit.

Source

pub fn bytes(&mut self, ty: &Type) -> Result<&'b [u8], DecodeError>

Reads Bytes.

§Errors

As ValueReader::unit.

Source

pub fn host(&mut self, ty: &Type) -> Result<&'b str, DecodeError>

Reads a host type’s value, its token.

§Errors

As ValueReader::unit.

Source

pub fn list<T: Shaped>(&mut self, ty: &Type) -> Result<Vec<T>, DecodeError>

Reads a list.

§Errors

When ty is no list, or the bytes are not one of Ts.

Source

pub fn set<T: Shaped + Ord>( &mut self, ty: &Type, ) -> Result<BTreeSet<T>, DecodeError>

Reads a set, its elements in ascending order.

§Errors

When ty is no set, the bytes are not one of Ts, or its elements are out of order or repeat.

Source

pub fn dict<K: Shaped + Ord, V: Shaped>( &mut self, ty: &Type, ) -> Result<BTreeMap<K, V>, DecodeError>

Reads a dictionary, its entries in ascending order of their keys.

§Errors

When ty is no dictionary, the bytes are not one of Ks and Vs, or its keys are out of order or repeat.

Source

pub fn tuple<T>( &mut self, ty: &Type, read: impl FnOnce(&mut Self, &mut Fields) -> Result<T, DecodeError>, ) -> Result<T, DecodeError>

Reads a tuple, its parts by read.

§Errors

When ty is no tuple, or read refuses or leaves a part unread.

Source

pub fn record<T>( &mut self, ty: &Type, read: impl FnOnce(&mut Self, &mut Fields) -> Result<T, DecodeError>, ) -> Result<T, DecodeError>

Reads a record, its fields by read in declaration order.

§Errors

When ty is no record, or read refuses or leaves a field unread.

Source

pub fn variant<T>( &mut self, ty: &Type, read: impl FnOnce(&mut Self, usize, &mut Fields) -> Result<T, DecodeError>, ) -> Result<T, DecodeError>

Reads a value of the enum ty, Option and Result included: read is given its constructor’s index and reads its payload.

§Errors

When ty is no enum, the bytes name a constructor it does not have, or read refuses or leaves a part unread.

Source

pub fn newtype<T: Shaped>(&mut self, ty: &Type) -> Result<T, DecodeError>

Reads a value of the newtype ty as its base’s T, held to the form ty has, if any.

§Errors

When ty is no newtype, the bytes are not a T of its base, or the value is out of its form.

Source

pub fn encoded(&mut self, ty: &Type) -> Result<&'b [u8], DecodeError>

Reads one value of ty, checked as crate::read_value checks it, and gives its bytes.

§Errors

When the bytes are not a value of ty within the limits.

Trait Implementations§

Source§

impl<'c, 'r, 'b> Debug for ValueReader<'c, 'r, 'b>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'c, 'r, 'b> !UnwindSafe for ValueReader<'c, 'r, 'b>

§

impl<'c, 'r, 'b> Forget for ValueReader<'c, 'r, 'b>

§

impl<'c, 'r, 'b> Freeze for ValueReader<'c, 'r, 'b>
where &'c Catalog: Freeze, &'c Limits: Freeze, *const u8 is !null: Freeze, PhantomData<Step>: Freeze, &'r mut Reader<'b>: Freeze,

§

impl<'c, 'r, 'b> Move for ValueReader<'c, 'r, 'b>

§

impl<'c, 'r, 'b> RefUnwindSafe for ValueReader<'c, 'r, 'b>

§

impl<'c, 'r, 'b> Send for ValueReader<'c, 'r, 'b>
where &'c Catalog: Send, &'c Limits: Send, RawVecInner: Send, &'b [u8]: Send,

§

impl<'c, 'r, 'b> Sync for ValueReader<'c, 'r, 'b>
where RawVecInner: Sync, Arc<RecordShape>: Sync, BoxRaw<Type>: Sync, Arc<EnumShape>: Sync, Mutex<HashMap<(Type, Settings), Option<String>>>: Sync, RawTable<(Box<str>, usize)>: Sync, BoxRaw<[usize]>: Sync, BoxRaw<[Option<OptionCtor>]>: Sync, BoxRaw<[Option<JsonValueCtor>]>: Sync,

§

impl<'c, 'r, 'b> Unpin for ValueReader<'c, 'r, 'b>
where &'c Catalog: Unpin, &'c Limits: Unpin, *const u8 is !null: Unpin, &'r mut Reader<'b>: Unpin,

§

impl<'c, 'r, 'b> UnsafeUnpin for ValueReader<'c, 'r, 'b>

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.