pub struct RequireKeys;Expand description
Every declared field required to be present, and every unknown key still refused.
The policy for a document that is meant to carry the whole value rather
than a patch over one. It is the exact opposite of SkipUnknown: that
one accepts a document that says more than the schema does, this one
refuses a document that says less.
For a schema where only some members are mandatory, which is most of them,
mark those #[required] in the declaration and read under the default
policy. This is the blunt instrument, and it is the right one only where
every member really is mandatory.
use structio::{ErrorCode, RequireKeys, from_str, from_str_with};
let doc = r#"{"x":1.0}"#;
assert_eq!(from_str::<Point>(doc).unwrap().y, 0.0);
assert_eq!(
from_str_with::<RequireKeys, Point>(doc).unwrap_err().code,
ErrorCode::MissingKey
);Trait Implementations§
Source§impl Clone for RequireKeys
impl Clone for RequireKeys
Source§fn clone(&self) -> RequireKeys
fn clone(&self) -> RequireKeys
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for RequireKeys
Source§impl Debug for RequireKeys
impl Debug for RequireKeys
Source§impl Default for RequireKeys
impl Default for RequireKeys
Source§fn default() -> RequireKeys
fn default() -> RequireKeys
Returns the “default value” for a type. Read more
impl Eq for RequireKeys
Source§impl Hash for RequireKeys
impl Hash for RequireKeys
Source§impl Options for RequireKeys
impl Options for RequireKeys
Source§const ERROR_ON_MISSING_KEYS: bool = true
const ERROR_ON_MISSING_KEYS: bool = true
Refuse a document that leaves a declared field out. Read more
Source§const PRETTY: bool = false
const PRETTY: bool = false
Write JSON across multiple lines, indented by nesting depth. Read more
Source§const NEW_LINES_IN_ARRAYS: bool = true
const NEW_LINES_IN_ARRAYS: bool = true
Source§const ERROR_ON_UNKNOWN_KEYS: bool = true
const ERROR_ON_UNKNOWN_KEYS: bool = true
Refuse a document that holds a key no field claims. Read more
Source§const ALLOW_COMMENTS: bool = false
const ALLOW_COMMENTS: bool = false
Source§impl PartialEq for RequireKeys
impl PartialEq for RequireKeys
impl StructuralPartialEq for RequireKeys
Auto Trait Implementations§
impl Freeze for RequireKeys
impl RefUnwindSafe for RequireKeys
impl Send for RequireKeys
impl Sync for RequireKeys
impl Unpin for RequireKeys
impl UnsafeUnpin for RequireKeys
impl UnwindSafe for RequireKeys
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