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

Add mutable RecvMsgOut #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SUPERCILEX
Copy link
Contributor

Parsing control data usually requires mutation to be safe (so parsing the same slice doesn't return multiple OwnedFds that point to the same FD).

I had to make the buffer fields public and use unsafe which is annoying, but since rust can't prove we don't alias the buffer it's the only way to get multiple slices out of it AFAIK.

Signed-off-by: Alex Saveau <[email protected]>
@quininer
Copy link
Member

quininer commented Feb 18, 2024

I don't really like this macro, is it possible to implement it using generics?

like

pub struct RecvMsgOut<BUF: MsgBuf> {
    // ...
}

trait MsgBuf {
    type Pointer: Copy;

    fn from_raw_parts(ptr: Self::Pointer, len: usize) -> Self;
    fn as_ptr(&self) -> Self::Pointer;
}

impl MsgBuf for &[u8] {
    type Pointer = *const u8;

    // ...
}

impl MsgBuf for &mut [u8] {
    type Pointer = *mut u8;

    // ...
}

@SUPERCILEX
Copy link
Contributor Author

SUPERCILEX commented Feb 18, 2024

Sorry, I'm a little unclear on what you're suggesting. What does the public API look like? Do we still have public fields with different mutability? Or are we keeping the public methods and implementing mutable variants when the generic parse input is a mut slice? And then does that mean we use unsafe to create the slices rather than store them in the struct?

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.

None yet

2 participants