Thomasdezeeuw / gaea

Low-level library to build event driven applications, supporting lightweight non-blocking I/O.
https://docs.rs/gaea/
MIT License
16 stars 0 forks source link

Fix the need for generic parameters in calls to poll #64

Closed Thomasdezeeuw closed 5 years ago

Thomasdezeeuw commented 5 years ago

Currently poll has two generic parameters of which the error is almost never inferred, e.g. from the example of the crate docs.

poll::<_, io::Error>(&mut [&mut os_queue], &mut events, None)?;
//    ^^^^^^^^^^^^^^ Don't like this.
Thomasdezeeuw commented 5 years ago

I don't really see a solution for this. The easiest way to remove the need for the generic parameter is to wrap the call to poll in your own method that returns an error. For example:

struct MyEvents {
    events: Vec<Event>,
    os_queue: OsQueue,
    timers: Timers,
}

impl MyEvents {
    pub fn poll(&mut self) -> Result<(), io::Error> {
        // No need to specify the error type.
        poll(&mut [&mut self.os_queue, &mut self.timer], &mut self.events, None)
    }
}