pub fn default_atom(
sink: &mut dyn Sink<'_>,
atom: Atom<'_>,
state: &mut State,
) -> Result<(), Error>Expand description
The default handling of atoms, which is what Sink::atom does by
default.
Sinks pass the atoms they do not accept to this (and values the atoms
their deserialize_atom does
not accept, with the slot as sink). Some atoms are passed on to
Sink::atom of the sink again in another form:
Atom::Extvalues are lowered into the core data model with theirfallback(the input of raw values is parsed into the sink).Atom::F32is widened into anAtom::F64, so sinks that accept floats only need to handleF64.Atom::Lexicalis passed on asAtom::Str, so sinks that accept strings accept lexical atoms too.Atom::Implicitis passed on as its value and, if that is rejected, as its text (seeImplicit).
For all other atoms an error is returned that is based on
Sink::expecting of the sink, which is
Deserialize::expecting for a
Slot.
use deser::de::{Deserialize, Slot, default_atom};
use deser::{Atom, Error, State};
struct MyBool(bool);
impl<'de> Deserialize<'de> for MyBool {
fn deserialize_atom(
slot: &mut Slot<Self>,
atom: Atom,
state: &mut State,
) -> Result<(), Error> {
match atom {
Atom::Bool(value) => {
slot.set(MyBool(value));
Ok(())
}
other => default_atom(slot, other, state),
}
}
}
// a lexical atom is passed on as string, which is rejected
let mut out = None::<MyBool>;
let mut driver = deser::de::DeserializeDriver::new(&mut out);
let err = driver.emit(Atom::Lexical("true".into())).unwrap_err();
assert_eq!(err.message(), "unexpected string, expected MyBool");