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

Executors and System IO: self reference should be mutable #109

Open
uint opened this issue Oct 5, 2020 · 2 comments
Open

Executors and System IO: self reference should be mutable #109

uint opened this issue Oct 5, 2020 · 2 comments

Comments

@uint
Copy link

uint commented Oct 5, 2020

The Executors and System IO chapter includes a (pseudo-)code snippet that outlines how an IO blocking primitive is generally structured. This is minor, but shouldn't the self reference this function takes be mutable?

    /// Express an interest in a particular IO event.
    fn add_io_event_interest(
        &self,

        /// The object on which the event will occur
        io_object: &IoObject,

        /// A set of signals that may appear on the `io_object` for
        /// which an event should be triggered, paired with
        /// an ID to give to events that result from this interest.
        event: Event,
    ) { /* ... */ }

Later on in the same snippet, we specifically make the variable holding an IoBlocker mutable, presumably because it needs to be mutable to call add_io_event_interest on it.

let mut io_blocker = IoBlocker::new();
io_blocker.add_io_event_interest(
    &socket_1,
    Event { id: 1, signals: READABLE },
);
io_blocker.add_io_event_interest(
    &socket_2,
    Event { id: 2, signals: READABLE | WRITABLE },
);
let event = io_blocker.block();
@taiki-e
Copy link
Member

taiki-e commented Oct 9, 2020

I guess that implies the use of interior mutability.

@uint
Copy link
Author

uint commented Oct 9, 2020

@taiki-e I don't think so. Marking the variable that holds the "wrapper" type with mut isn't needed to take advantage of interior mutability.

Here's proof. Note this in particular:

    let foo = Foo::new("original");
    // ^-- no `mut` here

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

No branches or pull requests

2 participants