pub struct LexicalRules { /* private fields */ }Expand description
How lexical atoms are interpreted.
Lexical atoms are text whose type the format cannot express. The types
they are delivered to interpret them: numbers and booleans parse them,
strings take them as they are. What text means beyond that depends on
where it comes from. Keys of JSON objects are strict (a bool key is
true or false), everything in a query string or an environment
variable is text so on and yes are booleans too and empty values are
missing values.
The rules are an extension value, the default are the
strict rules. Formats where everything is text have
other defaults (query strings, environment variables and CSV use the
lenient rules), which rules in the
Context (or in the State, see
set) override. As they are part of the state (and not
of the atoms), lexical atoms that are buffered and replayed are
interpreted with the rules of the deserialization they are replayed in.
use deser::de::{DeserializeDriver, LexicalRules};
use deser::{Atom, Text};
let mut out = None::<bool>;
let mut driver = DeserializeDriver::new(&mut out);
LexicalRules::LENIENT.set(driver.state_mut());
driver.emit(Atom::Lexical(Text::borrowed("on"))).unwrap();
drop(driver);
assert_eq!(out, Some(true));Implementations§
Source§impl LexicalRules
impl LexicalRules
Sourcepub const STRICT: LexicalRules
pub const STRICT: LexicalRules
The rules for text that happens to be text, like the keys of JSON objects. This is the default.
- booleans are
trueandfalse - integers and floats are parsed with
str::parse - empty text is not a missing value
Sourcepub const LENIENT: LexicalRules
pub const LENIENT: LexicalRules
The rules for formats where everything is text, like query strings and environment variables.
- booleans are
true,yes,onand1andfalse,no,offand0(ignoring ASCII case) - integers and floats are parsed with
str::parse - empty text is a missing value for types that do not accept it:
Nonefor anOption<u32>,Some("")for anOption<String>and()
These formats typically also allow keys to repeat, a key given once
can then stand for a sequence of one value. That is not a rule of
the text but of the maps they emit (see
ContainerShape::set_multimap).
Sourcepub fn of(state: &State) -> LexicalRules
pub fn of(state: &State) -> LexicalRules
Returns the rules of a deserialization.
Sourcepub fn set_default(self, state: &mut State)
pub fn set_default(self, state: &mut State)
Sets the rules unless the state or the context has rules.
Formats use this for their default (see State::set_default).
Sourcepub const fn set_lenient_bools(&mut self, yes: bool)
pub const fn set_lenient_bools(&mut self, yes: bool)
Sets if booleans are also yes, on and 1 and no, off and
0 (ignoring ASCII case).
Sourcepub const fn lenient_bools(&self) -> bool
pub const fn lenient_bools(&self) -> bool
Returns true if booleans are also yes, on and 1 and no,
off and 0 (see set_lenient_bools).
Sourcepub const fn set_empty_is_null(&mut self, yes: bool)
pub const fn set_empty_is_null(&mut self, yes: bool)
Sets if empty text is a missing value for types that do not accept it.
Sourcepub const fn empty_is_null(&self) -> bool
pub const fn empty_is_null(&self) -> bool
Returns true if empty text is a missing value for types that do
not accept it (see set_empty_is_null).
Trait Implementations§
Source§impl Clone for LexicalRules
impl Clone for LexicalRules
impl Copy for LexicalRules
Source§impl Debug for LexicalRules
impl Debug for LexicalRules
Source§impl Default for LexicalRules
impl Default for LexicalRules
Source§fn default() -> LexicalRules
fn default() -> LexicalRules
impl Eq for LexicalRules
Source§impl PartialEq for LexicalRules
impl PartialEq for LexicalRules
impl StructuralPartialEq for LexicalRules
Auto Trait Implementations§
impl Freeze for LexicalRules
impl RefUnwindSafe for LexicalRules
impl Send for LexicalRules
impl Sync for LexicalRules
impl Unpin for LexicalRules
impl UnsafeUnpin for LexicalRules
impl UnwindSafe for LexicalRules
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.