-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Due to new requirements, I tried to make a derive proc macro and found some previous unreasonable designs.
-
Nullis not suitable forOption<T>because it cannot distinguishOption<Option<T>>Lines 738 to 749 in 01b3c1f
impl<'de, T: Decode<'de>> Decode<'de> for Option<T> { #[inline] fn decode<R: Read<'de>>(reader: &mut R) -> Result<Self, Error<R::Error>> { let byte = peek_one(&"option", reader)?; if byte != marker::NULL && byte != marker::UNDEFINED { T::decode(reader).map(Some) } else { reader.advance(1); Ok(None) } } } -
The
Wgeneric constraint ofencodeis on the method rather than trait, which makes the trait unusable as a dyn object. I actually thought about this, we could doimpl<W: Write, T: Encode> DynEncode<W> for T, but this is not convenient.Line 22 in 01b3c1f
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), Error<W::Error>>; -
The
wantinRead::fillis not mandatory. I designed it thinking it could be used as an optimization, but I don't believe anyone does that. We can remove it.Furthermore, we should deprecateLine 27 in 01b3c1f
fn fill<'short>(&'short mut self, want: usize) -> Result<Reference<'de, 'short>, Self::Error>; filland movepeek_oneandpull_exactdirectly intoReadtrait, so thatSliceReaderhas less overhead. -
I used
&&strto save the size of Error type, but we could have just usedu8as error kind.Line 347 in 01b3c1f
let name = &"u128";
Despite my thoughts, I don't think 2.0.0 will happen anytime soon, and it shouldn't have any impact on serde users.