FromRef
All checks were successful
buildbot/cargo fmt (1.71) Build done.
buildbot/cargo clippy (1.71) Build done.
buildbot/cargo doc (1.71) Build done.
buildbot/cargo test (1.65) Build done.
buildbot/cargo clippy (1.65) Build done.

This commit is contained in:
AF 2023-08-11 13:30:36 +00:00
parent 174ca78e55
commit 73c2498fbf
7 changed files with 14 additions and 6 deletions

View File

@ -24,7 +24,7 @@ pub use self::inlining::InliningMode;
pub use self::regular::RegularMode; pub use self::regular::RegularMode;
pub use self::serialization::{Deserializer, DeserializerExt, Serializable, Serializer}; pub use self::serialization::{Deserializer, DeserializerExt, Serializable, Serializer};
pub use self::slice_deserializer::SliceDeserializer; pub use self::slice_deserializer::SliceDeserializer;
pub use self::stream::{Stream, StreamExt, StreamResultExt}; pub use self::stream::{FromRef, Stream, StreamExt, StreamResultExt};
/// See [`ModeResult`]. /// See [`ModeResult`].
pub type ParseSuccess<M, A, I> = <M as Mode>::ParseSuccess<A, I>; pub type ParseSuccess<M, A, I> = <M as Mode>::ParseSuccess<A, I>;

View File

@ -70,3 +70,11 @@ impl<A, E, I: Stream> StreamResultExt<A, E> for Result<(A, I), E> {
self.map(|(a, _)| a) self.map(|(a, _)| a)
} }
} }
pub trait FromRef<T: ?Sized>: for<'a> From<&'a T> {
fn from_ref(value: &T) -> Self {
Self::from(value)
}
}
impl<T: ?Sized, U: for<'a> From<&'a T>> FromRef<T> for U {}

View File

@ -48,7 +48,7 @@ impl<const N: usize> CInliningAtomic for [u8; N] {
} }
fn ca_ideserialize<I: Stream>(stream: I) -> AIParseResult<Self, I> { fn ca_ideserialize<I: Stream>(stream: I) -> AIParseResult<Self, I> {
stream.iread_n_const::<N>(|slice| ArrayParseError::from(slice)) stream.iread_n_const::<N>(ArrayParseError::from_ref)
} }
} }

View File

@ -48,7 +48,7 @@ impl CInliningAtomic for u64 {
} }
fn ca_ideserialize<I: Stream>(stream: I) -> AIParseResult<Self, I> { fn ca_ideserialize<I: Stream>(stream: I) -> AIParseResult<Self, I> {
let (x, stream) = stream.iread_n_const::<8>(|slice| IntParseError::from(slice))?; let (x, stream) = stream.iread_n_const::<8>(IntParseError::from_ref)?;
Ok((u64::from_le_bytes(x), stream)) Ok((u64::from_le_bytes(x), stream))
} }
} }

View File

@ -55,7 +55,7 @@ impl CInliningAtomic for bool {
} }
fn ca_ideserialize<I: Stream>(stream: I) -> AIParseResult<Self, I> { fn ca_ideserialize<I: Stream>(stream: I) -> AIParseResult<Self, I> {
let (byte, stream) = stream.iread_n_const::<1>(|slice| BooleanParseError::from(slice))?; let (byte, stream) = stream.iread_n_const::<1>(BooleanParseError::from_ref)?;
match byte[0] { match byte[0] {
0 => Ok((false, stream)), 0 => Ok((false, stream)),
1 => Ok((true, stream)), 1 => Ok((true, stream)),

View File

@ -126,7 +126,7 @@ impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> CInliningFactory<'a, Ctx>
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> { fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
let factory = self.factory.clone(); let factory = self.factory.clone();
let (address, inctx) = inctx.icnext_address(|slice| PointParseError::from(slice))?; let (address, inctx) = inctx.icnext_address(PointParseError::from_ref)?;
Ok(( Ok((
if address.point == HASH_ZEROS { if address.point == HASH_ZEROS {
Nullable::Null(factory) Nullable::Null(factory)

View File

@ -90,7 +90,7 @@ impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> CInliningFactory<'a, Ctx> fo
} }
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> { fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
inctx.icnext_point(self.inner(), |slice| PointParseError::from(slice)) inctx.icnext_point(self.inner(), PointParseError::from_ref)
} }
} }