Module calloop::generic

source ·
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};

handle.insert_source(
    // 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.
        Ok(PostAction::Continue)
    }
);

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.

Structs§

  • Wrapper to use a type implementing AsRawFd but not AsFd with Generic
  • A generic event source wrapping a FD-backed type
  • A wrapper around a type that doesn’t expose it mutably safely.