Struct FdSet

#[repr(transparent)]
pub struct FdSet<'fd> { /* private fields */ }

Contains a set of file descriptors used by select

Implementations

impl<'fd> FdSet<'fd>

fn new() -> FdSet<'fd>

Create an empty FdSet

fn insert(&mut self, fd: BorrowedFd<'fd>)

Add a file descriptor to an FdSet

fn remove(&mut self, fd: BorrowedFd<'fd>)

Remove a file descriptor from an FdSet

fn contains(&self, fd: BorrowedFd<'fd>) -> bool

Test an FdSet for the presence of a certain file descriptor.

fn clear(&mut self)

Remove all file descriptors from this FdSet.

fn highest(&self) -> Option<BorrowedFd<'_>>

Finds the highest file descriptor in the set.

Returns None if the set is empty.

This can be used to calculate the nfds parameter of the select function.

Example

# use std::os::unix::io::{AsRawFd, BorrowedFd};
# use nix::sys::select::FdSet;
let fd_four = unsafe {BorrowedFd::borrow_raw(4)};
let fd_nine = unsafe {BorrowedFd::borrow_raw(9)};
let mut set = FdSet::new();
set.insert(fd_four);
set.insert(fd_nine);
assert_eq!(set.highest().map(|borrowed_fd|borrowed_fd.as_raw_fd()), Some(9));
fn fds(&self, highest: Option<RawFd>) -> Fds<'_, '_>

Returns an iterator over the file descriptors in the set.

For performance, it takes an optional higher bound: the iterator will not return any elements of the set greater than the given file descriptor.

Examples

# use nix::sys::select::FdSet;
# use std::os::unix::io::{AsRawFd, BorrowedFd, RawFd};
let mut set = FdSet::new();
let fd_four = unsafe {BorrowedFd::borrow_raw(4)};
let fd_nine = unsafe {BorrowedFd::borrow_raw(9)};
set.insert(fd_four);
set.insert(fd_nine);
let fds: Vec<RawFd> = set.fds(None).map(|borrowed_fd|borrowed_fd.as_raw_fd()).collect();
assert_eq!(fds, vec![4, 9]);

Trait Implementations

impl Default for FdSet<'_>

fn default() -> Self

impl<'fd> Clone for FdSet<'fd>

fn clone(&self) -> Self

impl<'fd> Copy for FdSet<'fd>

impl<'fd> Debug for FdSet<'fd>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<'fd> Eq for FdSet<'fd>

impl<'fd> Hash for FdSet<'fd>

fn hash<__H: Hasher>(&self, state: &mut __H)

impl<'fd> PartialEq for FdSet<'fd>

fn eq(&self, other: &Self) -> bool

impl<'fd> StructuralPartialEq for FdSet<'fd>

Auto Trait Implementations

impl<'fd> Freeze for FdSet<'fd>

impl<'fd> RefUnwindSafe for FdSet<'fd>

impl<'fd> Send for FdSet<'fd>

impl<'fd> Sync for FdSet<'fd>

impl<'fd> Unpin for FdSet<'fd>

impl<'fd> UnsafeUnpin for FdSet<'fd>

impl<'fd> UnwindSafe for FdSet<'fd>

Blanket Implementations

impl<T> Any for FdSet<'fd> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for FdSet<'fd> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for FdSet<'fd> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for FdSet<'fd> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for FdSet<'fd>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for FdSet<'fd> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for FdSet<'fd> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for FdSet<'fd> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for FdSet<'fd> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>