pub struct Same;Expand description
The identity adapter: read and write this position the way the type itself would.
Adapters compose as types do, so a container adapter needs something to
name at a position that wants no adapting. Vec<Same> reads a Vec<T>
element for element as Vec<T>’s own impl does, and
HashMap<Same, Millis> adapts only a map’s values, leaving its keys to
FromJsonKey and
FromBeveKey.
One type rather than one per format, because a declaration names a single
adapter and the macro emits it against json::ReadAs,
json::WriteAs,
beve::ReadAs and
beve::WriteAs alike. A per-format Same could
not be written at a field at all.
It is an identity on the bytes too, not only on the values, and in both
directions: Same forwards BEVE’s
Write::ARRAY, so a Vec<Same> over a
Vec<f64> is still one typed array rather than a value per element, and it
forwards Read::read_bulk, so reading that
array back is still the single memcpy the unadapted field would have got.
Neither is true of an adapter in general, and neither should be. An adapter
with a conversion to do has no block to copy, so it leaves both alone and
gets a generic array and an element-by-element read. What Same shows is
that the ceiling is the adapter’s, not the mechanism’s: an adapter over a
type whose memory is already a payload can reach the same two paths, which
is what NumericBytes is implementable for.
Trait Implementations§
Source§impl<'de, T: Read<'de>> ReadAs<'de, T> for Same
impl<'de, T: Read<'de>> ReadAs<'de, T> for Same
Source§impl<T: FromBeveKey> ReadKeyAs<T> for Same
impl<T: FromBeveKey> ReadKeyAs<T> for Same
Source§impl<T: FromJsonKey> ReadKeyAs<T> for Same
impl<T: FromJsonKey> ReadKeyAs<T> for Same
Source§impl<T: Write + ?Sized> WriteAs<T> for Same
impl<T: Write + ?Sized> WriteAs<T> for Same
Source§const ARRAY: Option<&'static [u8]> = <T as Write>::ARRAY
const ARRAY: Option<&'static [u8]> = <T as Write>::ARRAY
The identity on the bytes as well as on the values: without this
forwarding a Vec<Same> would drop out of its typed array.