Skip to main content

Input

Struct Input 

Source
pub struct Input { /* private fields */ }
Available on crate features input-toml or input-yaml only.
Expand description

A named text, ready to parse and validate.

The name is usually the file’s path, and appears in every problem. Build one with Input::new_with_format for text in memory, or Input::open for a file. With input-yaml, Input::new and Input::read build a YAML one.

Implementations§

Source§

impl Input

Source

pub fn new(name: impl Into<String>, text: impl Into<String>) -> Self

Available on crate feature input-yaml only.

A YAML input from text already in memory, whatever the extension of name. Set another format with Input::format.

Source

pub fn new_with_format( name: impl Into<String>, text: impl Into<String>, format: Format, ) -> Self

An input of format from text already in memory, whatever the extension of name. It needs only format’s feature, so a build without YAML builds text in memory with it.

Source

pub fn read(path: &Path) -> Result<Self, InputError>

Available on crate feature input-yaml only.

Read a YAML file, named by its path, whatever its extension.

§Errors

An InputError with the I/O failure.

Source

pub fn open(path: &Path) -> Result<Self, InputError>

Read a file and take its Format from its extension, as Format::of does. The extension is checked before the file is read.

§Errors

An InputError for an extension Format::of refuses, or with the I/O failure.

Source

pub fn format(self, format: Format) -> Self

Set how the text is written, over what the constructor took.

Source

pub fn name(&self) -> &str

The name given at construction, usually the file’s path.

Source

pub fn text(&self) -> &str

The text as read, unchanged.

Source

pub fn frontmatter(&self) -> Option<(Self, &str)>

Available on crate feature input-yaml only.

Split YAML frontmatter from a Markdown body.

The frontmatter is the text between a first line of --- and the next line of ---. It is YAML whatever this input’s format, and problems in it keep the line numbers of the whole file. The second item is the body after the closing line. Returns None when the text does not start with a --- line, or never closes it.

Source

pub fn limits(self, limits: Limits) -> Self

Override limits for this input alone, above every other tier. See Limits for the order.

Source

pub fn parse<T: DeserializeOwned>(&self) -> Result<T, InputError>

Parse the text into T, without validating it.

In YAML only true and false are booleans, and a duplicate key or a merge key (<<) is refused. In TOML the format itself refuses a duplicate key.

The text must fit the limits in force, decided field by field through the tiers Limits lists. TOML reads only max_reader_input_bytes, max_depth, and max_nodes, because the other fields name YAML syntax.

§Errors

An InputError with the parser’s problem and its line. A limit problem names the limit, its value, and where to raise it, or, without input-yaml, that the tool sets it.

Source

pub fn check<T: Validate + ?Sized>( &self, value: &T, context: &T::Context, ) -> Result<(), InputError>

Available on crate feature validate only.

Validate a parsed value against context.

Each of garde’s problems lands on the line of the field it names, or of its nearest written ancestor.

§Errors

An InputError with every problem garde reports.

Source

pub fn load<T>(&self) -> Result<T, InputError>

Available on crate feature validate only.

Parse the text into T, then validate it with T’s default context.

§Errors

As Input::parse and Input::check.

Trait Implementations§

Source§

impl Clone for Input

Source§

fn clone(&self) -> Self

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 Input

Source§

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

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

impl Eq for Input

Source§

impl PartialEq for Input

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Input

Auto Trait Implementations§

§

impl Forget for Input

§

impl Freeze for Input

§

impl RefUnwindSafe for Input

§

impl Send for Input

§

impl Sync for Input

§

impl Unpin for Input

§

impl UnsafeUnpin for Input

§

impl UnwindSafe for Input

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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, O> Matches<O> for T
where T: PartialEq<O>,

Source§

fn validate_matches(&self, other: &O) -> bool

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