very elegant extension API and parts of it used in std as POC

This commit is contained in:
2024-07-01 20:11:22 +02:00
parent 93867e40c6
commit fc8441f080
63 changed files with 2040 additions and 925 deletions

View File

@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::hash::Hash;
use std::io::{Read, Write};
@@ -282,6 +283,15 @@ smart_ptr!(Arc);
smart_ptr!(Rc);
smart_ptr!(Box);
impl<'a, T: ?Sized + ToOwned> Decode for Cow<'a, T>
where T::Owned: Decode
{
fn decode<R: Read + ?Sized>(read: &mut R) -> Self { Cow::Owned(T::Owned::decode(read)) }
}
impl<'a, T: ?Sized + Encode + ToOwned> Encode for Cow<'a, T> {
fn encode<W: Write + ?Sized>(&self, write: &mut W) { (**self).encode(write) }
}
impl Decode for char {
fn decode<R: Read + ?Sized>(read: &mut R) -> Self { char::from_u32(u32::decode(read)).unwrap() }
}