Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign ignore #11

Closed
mitsuhiko opened this issue Feb 7, 2022 · 2 comments
Closed

Redesign ignore #11

mitsuhiko opened this issue Feb 7, 2022 · 2 comments
Labels
defect Design defect enhancement New feature or request

Comments

@mitsuhiko
Copy link
Owner

deser currently inherits the design for ignore from miniserde. It involves creating a mutable reference to some static Sink. Miri complains about this and it does sound dodgy. I definitely get miri failures from this when I use ignore and I was also able to reproduce the same issue in miniserde: dtolnay/miniserde#24

The solution for deser would be to embed a zero sized type Ignore directly in the SinkHandle like so:

pub enum SinkHandle<'a> {
    Borrowed(&'a mut dyn Sink),
    Owned(Box<dyn Sink + 'a>),
    Null(Ignore),
}

Ignore can stay internal and SinkHandle gets a new method to create it (SinkHandle::null()) to replace SinkHandle::to(ignore()). This is also more convenient to use for a user.

Size of the enum should stay the same I think.

@mitsuhiko mitsuhiko added defect Design defect enhancement New feature or request labels Feb 7, 2022
@mitsuhiko
Copy link
Owner Author

It would appear that this is okay for zero sized types: rust-lang/rust-memory-model#44

That said, I'm not convinced this unsafe monkey business is actually needed in this case as keeping the Ignore directly in the SinkHandle is possible. At the very least I vastly prefer calling SinkHandle::null over having to make a SinkHandle manually and calling ignore().

@mitsuhiko
Copy link
Owner Author

I changed this now to SinkHandle::null().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Design defect enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant