Skip to content

Simplify lifetimes#16

Open
ma2bd wants to merge 1 commit intozefchain:mainfrom
ma2bd:simplify-lifetimes
Open

Simplify lifetimes#16
ma2bd wants to merge 1 commit intozefchain:mainfrom
ma2bd:simplify-lifetimes

Conversation

@ma2bd
Copy link
Copy Markdown
Contributor

@ma2bd ma2bd commented Apr 17, 2026

Bringing back #9 from @Twey

Summary

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).

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`).
Comment thread src/ser.rs
Comment on lines +73 to 75
pub fn serialize_into<T>(mut write: impl std::io::Write, value: &T) -> Result<()>
where
W: ?Sized + std::io::Write,
T: ?Sized + Serialize,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think losing the W: ?Sized bound is a real functional loss right? trait objects would no longer be usable via this api.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm good question. Let me check

Comment thread src/de.rs
Comment on lines +157 to +160
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 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone submitted this PR: #15

Comment thread src/ser.rs
Comment on lines +83 to +84
pub fn serialize_into_with_limit<T>(
mut write: impl std::io::Write,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i would probably keep the generic bounds but we could have this just be W instead of &mut W

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants