Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<'r> {
    pub problems: Vec<Problem>,
    pub refs: Vec<Found<Ref>>,
    pub tags: Vec<Found<Ref>>,
    pub resources: Vec<Found<Res>>,
    /* private fields */
}
Expand description

The state of reading a value: where it is, the problems so far, and the references met (for the build to check against the content there is).

Fields§

§problems: Vec<Problem>§refs: Vec<Found<Ref>>§tags: Vec<Found<Ref>>§resources: Vec<Found<Res>>

Implementations§

Source§

impl<'r> Reader<'r>

Source

pub fn new() -> Self

Source

pub fn with_resolver(resolver: &'r mut dyn Resolve) -> Self

A reader handing references and texts to resolver.

Source

pub fn resolve_ref(&mut self, r: &Ref) -> Option<String>

r resolved (a problem if it’s wrong); its id without a resolver.

Source

pub fn resolve_text(&mut self, t: &Text) -> Option<String>

t resolved (a problem if it’s wrong).

Source

pub fn words(&mut self, r: &Res) -> Option<String>

The words of .yres text r, if the resolver knows them.

Source

pub fn path(&self) -> &Path

Source

pub fn problem(&mut self, message: impl Into<String>)

Reports a problem with the value being read.

Source

pub fn expected(&mut self, what: &str, found: &Value)

“expected X, found Y”.

Source

pub fn at<T>(&mut self, seg: Seg, f: impl FnOnce(&mut Self) -> T) -> T

Runs f one step deeper.

Source

pub fn note_ref(&mut self, r: Ref)

Source

pub fn note_tag(&mut self, r: Ref)

Source

pub fn note_res(&mut self, r: Res)

Source

pub fn map<'v>(&mut self, v: &'v Value) -> Option<&'v Map>

v as an object, or a problem.

Source

pub fn unknown_keys(&mut self, map: &Map, known: &[&str])

Reports keys of map that aren’t known (nor metadata, nor allowed by an enclosing enum).

Source

pub fn unknown_name(&mut self, name: &str, known: &[&str])

Reports a name that isn’t one of known (an enum’s variant).

Source

pub fn field<T: Schema>(&mut self, map: &Map, key: &'static str) -> Option<T>

Field key of map: read, or its absent value, or a problem.

Source

pub fn field_or<T: Schema>( &mut self, map: &Map, key: &'static str, default: impl FnOnce() -> T, ) -> Option<T>

Field key of map, default() when it isn’t there.

Source

pub fn field_with<W: With<F>, F>( &mut self, map: &Map, key: &'static str, ) -> Option<F>

Field key of map through codec W.

Source

pub fn field_or_with<W: With<F>, F>( &mut self, map: &Map, key: &'static str, default: impl FnOnce() -> F, ) -> Option<F>

Field key of map through codec W, default() when it isn’t there.

Source

pub fn with_allowed<T>( &mut self, key: &'static str, f: impl FnOnce(&mut Self) -> T, ) -> T

Reads v as T with key allowed in it — the tag of the enum variant T is.

Source

pub fn with_allowed_all<T>( &mut self, keys: &[&'static str], f: impl FnOnce(&mut Self) -> T, ) -> T

Reads with every one of keys allowed (the fields of a struct read from the same object — see read_both).

Source

pub fn own_keys<T>(&mut self, f: impl FnOnce(&mut Self) -> T) -> T

Reads a struct’s own keys with no allowance inherited from outside.

Trait Implementations§

Source§

impl<'r> Default for Reader<'r>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'r> !RefUnwindSafe for Reader<'r>

§

impl<'r> !Send for Reader<'r>

§

impl<'r> !Sync for Reader<'r>

§

impl<'r> !UnwindSafe for Reader<'r>

§

impl<'r> Freeze for Reader<'r>

§

impl<'r> Unpin for Reader<'r>

§

impl<'r> UnsafeUnpin for Reader<'r>

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