pub struct Input { /* private fields */ }Expand description
A named text, ready to parse and validate.
Implementations§
Source§impl Input
impl Input
Sourcepub fn new(name: impl Into<String>, text: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, text: impl Into<String>) -> Self
A YAML input from text already in memory, whatever its name says. Set
another format with Input::format.
Sourcepub fn read(path: &Path) -> Result<Self, InputError>
pub fn read(path: &Path) -> Result<Self, InputError>
Read a YAML file, named by its path, whatever its extension.
§Errors
An InputError with the I/O failure.
Sourcepub fn open(path: &Path) -> Result<Self, InputError>
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.
Sourcepub fn format(self, format: Format) -> Self
pub fn format(self, format: Format) -> Self
Set how the text is written, over what Input::new assumed.
Sourcepub fn frontmatter(&self) -> Option<(Self, &str)>
pub fn frontmatter(&self) -> Option<(Self, &str)>
Split YAML frontmatter from a Markdown body: the text between a first
line of --- and the next line of ---. The frontmatter is YAML
whatever this input’s format. Problems in the frontmatter keep the
line numbers of the whole file. None when the text does not start
with a --- line, or never closes it.
Sourcepub fn limits(self, limits: Limits) -> Self
pub fn limits(self, limits: Limits) -> Self
Override limits for this input alone, above every other tier: see
Limits for the order.
Sourcepub fn parse<T: DeserializeOwned>(&self) -> Result<T, InputError>
pub fn parse<T: DeserializeOwned>(&self) -> Result<T, InputError>
Parse the text’s shape. In YAML only true and false are booleans,
and a duplicate key or a merge key (<<) is refused; in TOML a
duplicate key is refused by the format. The text must fit the limits in
force, field by field from this input, the repository’s
REPO_FILE, the process default, and serde-saphyr’s own defaults.
TOML reads only max_reader_input_bytes, max_depth, and max_nodes
from them: 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.
Sourcepub fn check<T: Validate + ?Sized>(
&self,
value: &T,
context: &T::Context,
) -> Result<(), InputError>
pub fn check<T: Validate + ?Sized>( &self, value: &T, context: &T::Context, ) -> Result<(), InputError>
Validate a parsed value against context, and place each of garde’s
problems on the line of the field it names, or of its nearest written
ancestor.
§Errors
An InputError with every problem garde reports.
Sourcepub fn load<T>(&self) -> Result<T, InputError>
pub fn load<T>(&self) -> Result<T, InputError>
Trait Implementations§
impl Eq for Input
impl StructuralPartialEq for Input
Auto Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more