Expand description

A generic event source wrapping an IO objects or file descriptor

You can use this general purpose adapter around file-descriptor backed objects to insert into an EventLoop.

The event generated by this Generic event source are the Readiness notification itself, and the monitored object is provided to your callback as the second argument.

use calloop::{generic::Generic, Interest, Mode, PostAction};

    // wrap your IO object in a Generic, here we register for read readiness
    // in level-triggering mode
    Generic::new(io_object, Interest::READ, Mode::Level),
    |readiness, io_object, shared_data| {
        // The first argument of the callback is a Readiness
        // The second is a &mut reference to your object

        // your callback needs to return a Result<PostAction, std::io::Error>
        // if it returns an error, the event loop will consider this event
        // event source as erroring and report it to the user.

It can also help you implementing your own event sources: just have these Generic<_> as fields of your event source, and delegate the EventSource implementation to them.

If you need to directly work with a RawFd, rather than an FD-backed object, see Generic::from_fd.


A generic event source wrapping a FD-backed type