Simplify lifetimes#16
Conversation
Since `&'a mut R` is `Read` (or `Write`) when `R` is `Read` (resp. `Write`), there is no need to depend on `<R: ?Sized + Read> &'a mut R` over just plain `<R: Read> R`. The caller can still instantiate `R = &'a mut R_` when a reference is desired (and indeed this is done here for e.g. `MapDeserializer`).
| pub fn serialize_into<T>(mut write: impl std::io::Write, value: &T) -> Result<()> | ||
| where | ||
| W: ?Sized + std::io::Write, | ||
| T: ?Sized + Serialize, |
There was a problem hiding this comment.
I think losing the W: ?Sized bound is a real functional loss right? trait objects would no longer be usable via this api.
There was a problem hiding this comment.
Mmm good question. Let me check
There was a problem hiding this comment.
There is no loss of functionality: &mut W was always sized even when W was not Sized.
| impl<R> Deserializer<R> { | ||
| /// Creates a new `Deserializer` which will be deserializing the provided | ||
| /// input. | ||
| fn new(input: &'de [u8], max_remaining_depth: usize) -> Self { | ||
| fn new(input: R, max_remaining_depth: usize) -> Self { |
There was a problem hiding this comment.
Not something that we really need to deal with right now but it would be interesting if we could restructure this crate to be able to operate in no_std environments since afaik the only usage of std we really have today is via the std::io traits
| pub fn serialize_into_with_limit<T>( | ||
| mut write: impl std::io::Write, |
There was a problem hiding this comment.
yeah i would probably keep the generic bounds but we could have this just be W instead of &mut W
There was a problem hiding this comment.
Same thing: We're basically replacing &mut (impl std::io::Write + ?Sized) by impl std::io::Write which is more general.
Bringing back #9 from @Twey
Summary
Since
&'a mut RisRead(orWrite) whenRisRead(resp.Write), there is no need to depend on<R: ?Sized + Read> &'a mut Rover just plain<R: Read> R. The caller can still instantiateR = &'a mut R_when a reference is desired (and indeed this is done here for e.g.MapDeserializer).