Enum jomini::json::TypeNarrowing
source · pub enum TypeNarrowing {
All,
Unquoted,
None,
}
Expand description
Controls when a value is attempted to be narrowed to a more specific type
Variants§
All
Attempt to narrow all values to more specific type
use jomini::{TextTape, json::{JsonOptions, TypeNarrowing}};
let tape = TextTape::from_slice(br#"a="01" b=02 c="yes" d=no"#)?;
let reader = tape.windows1252_reader();
let options = JsonOptions::new()
.with_type_narrowing(TypeNarrowing::All);
let actual = reader.json()
.with_options(options)
.to_string();
assert_eq!(actual, r#"{"a":1,"b":2,"c":true,"d":false}"#);
Unquoted
Only attempt to narrow unquoted values to a more specific type
use jomini::{TextTape, json::{JsonOptions, TypeNarrowing}};
let tape = TextTape::from_slice(br#"a="01" b=02 c="yes" d=no"#)?;
let reader = tape.windows1252_reader();
let options = JsonOptions::new()
.with_type_narrowing(TypeNarrowing::Unquoted);
let actual = reader.json()
.with_options(options)
.to_string();
assert_eq!(actual, r#"{"a":"01","b":2,"c":"yes","d":false}"#);
None
Don’t attempt any narrowing (all values will be strings)
use jomini::{TextTape, json::{JsonOptions, TypeNarrowing}};
let tape = TextTape::from_slice(br#"a="01" b=02 c="yes" d=no"#)?;
let reader = tape.windows1252_reader();
let options = JsonOptions::new()
.with_type_narrowing(TypeNarrowing::None);
let actual = reader.json()
.with_options(options)
.to_string();
assert_eq!(actual, r#"{"a":"01","b":"02","c":"yes","d":"no"}"#);
Trait Implementations§
source§impl Clone for TypeNarrowing
impl Clone for TypeNarrowing
source§fn clone(&self) -> TypeNarrowing
fn clone(&self) -> TypeNarrowing
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for TypeNarrowing
impl Debug for TypeNarrowing
source§impl PartialEq for TypeNarrowing
impl PartialEq for TypeNarrowing
source§fn eq(&self, other: &TypeNarrowing) -> bool
fn eq(&self, other: &TypeNarrowing) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Copy for TypeNarrowing
impl Eq for TypeNarrowing
impl StructuralPartialEq for TypeNarrowing
Auto Trait Implementations§
impl Freeze for TypeNarrowing
impl RefUnwindSafe for TypeNarrowing
impl Send for TypeNarrowing
impl Sync for TypeNarrowing
impl Unpin for TypeNarrowing
impl UnwindSafe for TypeNarrowing
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
Mutably borrows from an owned value. Read more