Struct AllowStd

Source
pub struct AllowStd<T>(pub T);
Expand description

A simple new type wrapper holding a potential reader or writer.

This type allows the library to satisfy the compatibility across different features without having to resort to specialization. Simply put, this struct implements Read and Write:

  • for all types that implement the respective trait from std if the std feature is active.
  • on a concrete subset of those types if the alloc feature but not the std feature has been turned on.
  • only for types from core when neither feature is turned on.

Note that without this type we couldn’t safely introduce a conditionally active, generic impl of our own traits. The reason is that features must only activate SemVer compatible changes. These two sets of impls are not SemVer compatible due to the uncovered generic T. In particular in the first case you’d be allowed to implement the trait for your own type that also implements std::io::Read while in the second this is an impl conflict.

  • impl Read for &'_ [u8]
  • impl<T> Read for T where std::io::Read

By adding our own private struct as a layer of indirection, you are no longer allowed to make such changes:

  • impl Read for AllowStd<&'_ [u8]>
  • impl<T> Read for AllowStd<T> where T: std::io::Read

This still means there is one impl which will never be added. Instead, the impls for core/standard types are provided separately and individually.

  • impl<T> Read for AllowStd<T> where T: crate::Read

Tuple Fields§

§0: T

Auto Trait Implementations§

§

impl<T> Freeze for AllowStd<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for AllowStd<T>
where T: RefUnwindSafe,

§

impl<T> Send for AllowStd<T>
where T: Send,

§

impl<T> Sync for AllowStd<T>
where T: Sync,

§

impl<T> Unpin for AllowStd<T>
where T: Unpin,

§

impl<T> UnwindSafe for AllowStd<T>
where T: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.