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 in the State (see
State::get_mut) which formats set, the default are the
strict rules. 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::with_multimap).
Sourcepub fn of(state: &State) -> LexicalRules
pub fn of(state: &State) -> LexicalRules
Returns the rules of a deserialization.
Sourcepub const fn with_lenient_bools(self, yes: bool) -> LexicalRules
pub const fn with_lenient_bools(self, yes: bool) -> LexicalRules
Sets if booleans are also yes, on and 1 and no, off and
0 (ignoring ASCII case).
Sourcepub const fn with_empty_is_null(self, yes: bool) -> LexicalRules
pub const fn with_empty_is_null(self, yes: bool) -> LexicalRules
Sets if empty text is a missing value for types that do not accept it.
Sourcepub const fn lenient_bools(&self) -> bool
pub const fn lenient_bools(&self) -> bool
Returns true if booleans are also yes, on, 1, no, off
and 0.
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.
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.