# [−][src]Struct mio::Registration

    pub struct Registration { /* fields omitted */ }

Handle to a user space `Poll` registration.

`Registration` allows implementing `Evented` for types that cannot work with the system selector. A `Registration` is always paired with a `SetReadiness`, which allows updating the registration's readiness state. When `set_readiness` is called and the `Registration` is associated with a `Poll` instance, a readiness event will be created and eventually returned by `poll`.

A `Registration` / `SetReadiness` pair is created by calling `Registration::new2`. At this point, the registration is not being monitored by a `Poll` instance, so calls to `set_readiness` will not result in any readiness notifications.

`Registration` implements `Evented`, so it can be used with `Poll` using the same `register`, `reregister`, and `deregister` functions used with TCP, UDP, etc... types. Once registered with `Poll`, readiness state changes result in readiness events being dispatched to the `Poll` instance with which `Registration` is registered.

Note, before using `Registration` be sure to read the `set_readiness` documentation and the portability notes. The guarantees offered by `Registration` may be weaker than expected.

For high level documentation, see `Poll`.

# Examples

    use mio::{Ready, Registration, Poll, PollOpt, Token};
    use mio::event::Evented;

    use std::io;
    use std::time::Instant;
    use std::thread;

    pub struct Deadline {
        when: Instant,
        registration: Registration,
    }

    impl Deadline {
        pub fn new(when: Instant) -> Deadline {
            let (registration, set_readiness) = Registration::new2();

            thread::spawn(move || {
                let now = Instant::now();

                if now < when {
                    thread::sleep(when - now);
                }

                set_readiness.set_readiness(Ready::readable());
            });

            Deadline {
                when: when,
                registration: registration,
            }
        }

        pub fn is_elapsed(&self) -> bool {
            Instant::now() >= self.when
        }
    }

    impl Evented for Deadline {
        fn register(&self, poll: &Poll, token: Token, interest: Ready, opts: PollOpt)
            -> io::Result<()>
        {
            self.registration.register(poll, token, interest, opts)
        }

        fn reregister(&self, poll: &Poll, token: Token, interest: Ready, opts: PollOpt)
            -> io::Result<()>
        {
            self.registration.reregister(poll, token, interest, opts)
        }

        fn deregister(&self, poll: &Poll) -> io::Result<()> {
            poll.deregister(&self.registration)
        }
    }

## Methods

### `impl Registration`[src]

#### `pub fn new2() -> (Registration, SetReadiness)`[src]

Create and return a new `Registration` and the associated `SetReadiness`.

See struct documentation for more detail and `Poll` for high level documentation on polling.

# Examples

    use mio::{Events, Ready, Registration, Poll, PollOpt, Token};
    use std::thread;

    let (registration, set_readiness) = Registration::new2();

    thread::spawn(move || {
        use std::time::Duration;
        thread::sleep(Duration::from_millis(500));

        set_readiness.set_readiness(Ready::readable());
    });

    let poll = Poll::new()?;
    poll.register(&registration, Token(0), Ready::readable() | Ready::writable(), PollOpt::edge())?;

    let mut events = Events::with_capacity(256);

    loop {
        poll.poll(&mut events, None);

        for event in &events {
            if event.token() == Token(0) && event.readiness().is_readable() {
                return Ok(());
            }
        }
    }

## Trait Implementations

### `impl Evented for Registration`[src]

#### `fn register(
&self,
poll: &Poll,
token: Token,
interest: Ready,
opts: PollOpt
) -> Result<()>`[src]

Register `self` with the given `Poll` instance. Read more

#### `fn reregister(
&self,
poll: &Poll,
token: Token,
interest: Ready,
opts: PollOpt
) -> Result<()>`[src]

Re-register `self` with the given `Poll` instance. Read more

#### `fn deregister(&self, poll: &Poll) -> Result<()>`[src]

Deregister `self` from the given `Poll` instance Read more

### `impl Send for Registration`[src]

### `impl Drop for Registration`[src]

#### `fn drop(&mut self)`[src]

Executes the destructor for this type. Read more

### `impl Sync for Registration`[src]

### `impl Debug for Registration`[src]

#### `fn fmt(&self, fmt: &mut Formatter) -> Result`[src]

Formats the value using the given formatter. Read more

## Auto Trait Implementations

### `impl Unpin for Registration`

### `impl !UnwindSafe for Registration`

### `impl !RefUnwindSafe for Registration`

## Blanket Implementations

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `fn into(self) -> U`[src]

Performs the conversion.

### `impl<T> From<T> for T`[src]

#### `fn from(t: T) -> T`[src]

Performs the conversion.

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`[src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`[src]

Performs the conversion.

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

####
ⓘImportant traits for &'_ mut W

### Important traits for &'_ mut W

`impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized,`
`fn borrow_mut(&mut self) -> &mut T`[src]

Mutably borrows from an owned value. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

####
ⓘImportant traits for &'_ mut W

### Important traits for &'_ mut W

`impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized,`
`fn borrow(&self) -> &T`[src]

Immutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn type_id(&self) -> TypeId`[src]

Gets the `TypeId` of `self`. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)