Skip to main content

Same

Struct Same 

Source
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

Source§

fn read_bulk<O: Options>( out: &mut Vec<T>, n: usize, elem: u8, r: &mut Reader<'de, O>, ) -> Result<bool, ErrorCode>

The identity on the reading side of a block, as ARRAY is on the writing side: whatever the type would have done with the payload, including declining it.

Source§

fn read<O: Options>( value: &mut T, r: &mut Reader<'de, O>, ) -> Result<(), ErrorCode>

Read into value, from the reader’s current position. Read more
Source§

impl<'de, T: Read<'de>> ReadAs<'de, T> for Same

Source§

fn read<O: Options>( value: &mut T, p: &mut Parser<'de, O>, ) -> Result<(), ErrorCode>

Read into value, from the cursor’s current position. Read more
Source§

impl<T: FromBeveKey> ReadKeyAs<T> for Same

Source§

fn from_key(key: Key<'_>) -> Result<T, ErrorCode>

Convert a key to the key type, the counterpart of FromBeveKey::from_key.
Source§

impl<T: FromJsonKey> ReadKeyAs<T> for Same

Source§

fn from_key(key: &str) -> Result<T, ErrorCode>

Convert an unescaped key to the key type, the counterpart of FromJsonKey::from_key.
Source§

impl<T: Write + ?Sized> WriteAs<T> for Same

Source§

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.

Source§

fn write<O: Options>(value: &T, w: &mut Writer<'_, O>)

Write value. Read more
Source§

fn is_null(value: &T) -> bool

Whether the field is absent, and so is left out of an object under Options::SKIP_NULL. Read more
Source§

fn write_payload<O: Options>(items: &[T], w: &mut Writer<'_, O>)
where T: Sized,

Append items as the payload of a typed array whose header and count the caller has already written. Read more
Source§

impl<T: Write + ?Sized> WriteAs<T> for Same

Source§

fn write<O: Options>(value: &T, w: &mut Writer<'_, O>)

Write value. Read more
Source§

fn is_null(value: &T) -> bool

Whether the field is absent, and so is left out of an object under Options::SKIP_NULL. Read more
Source§

impl<T: ToBeveKey + ?Sized> WriteKeyAs<T> for Same

Source§

const OBJECT: u8 = T::OBJECT

The object header these keys are stored under, the same constant ToBeveKey::OBJECT carries. Read more
Source§

fn write_key<O: Options>(value: &T, w: &mut Writer<'_, O>)

Write the key, its length prefix or width included, and nothing after it.
Source§

impl<T: ToJsonKey + ?Sized> WriteKeyAs<T> for Same

Source§

fn write_key<O: Options>(value: &T, w: &mut Writer<'_, O>)

Write the key, quotes included, and nothing after it. Read more

Auto Trait Implementations§

§

impl Freeze for Same

§

impl RefUnwindSafe for Same

§

impl Send for Same

§

impl Sync for Same

§

impl Unpin for Same

§

impl UnsafeUnpin for Same

§

impl UnwindSafe for Same

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.