pub struct Fifo<R = UnspecifiedFifoElement, W = R>(/* private fields */);
Expand description
An object representing a Zircon fifo.
As essentially a subtype of Handle
, it can be freely interconverted.
Encodes the element type in the type. Defaults to ()
for the entry type to allow for untyped
IPC. Use Fifo::cast()
to convert an IPC-transferred fifo to one of the specific type required
that will support reads and writes.
Implementations§
Source§impl<R, W> Fifo<R, W>where
R: IntoBytes + FromBytes,
W: IntoBytes + FromBytes,
impl<R, W> Fifo<R, W>where
R: IntoBytes + FromBytes,
W: IntoBytes + FromBytes,
Sourcepub fn create(elem_count: usize) -> Result<(Fifo<R, W>, Fifo<W, R>), Status>
pub fn create(elem_count: usize) -> Result<(Fifo<R, W>, Fifo<W, R>), Status>
Create a pair of fifos and return their endpoints. Writing to one endpoint enqueues an element into the fifo from which the opposing endpoint reads.
Wraps the zx_fifo_create syscall.
Sourcepub fn write(&self, buf: &[W]) -> Result<usize, Status>
pub fn write(&self, buf: &[W]) -> Result<usize, Status>
Attempts to write some number of elements into the fifo. On success, returns the number of elements actually written.
Wraps zx_fifo_write.
Sourcepub fn write_one(&self, elem: &W) -> Result<(), Status>
pub fn write_one(&self, elem: &W) -> Result<(), Status>
Attempts to write a single element into the fifo.
Wraps zx_fifo_write.
Sourcepub unsafe fn write_raw(
&self,
buf: *const W,
count: usize,
) -> Result<usize, Status>
pub unsafe fn write_raw( &self, buf: *const W, count: usize, ) -> Result<usize, Status>
Attempts to write some number of elements into the fifo. On success, returns the number of elements actually written.
Wraps zx_fifo_write.
§Safety
The caller is responsible for ensuring buf
is valid to write to for count
elements.
Sourcepub fn read(&self, buf: &mut [R]) -> Result<usize, Status>
pub fn read(&self, buf: &mut [R]) -> Result<usize, Status>
Attempts to read some elements out of the fifo. On success, returns the number of elements actually read.
Wraps zx_fifo_read.
Sourcepub fn read_one(&self) -> Result<R, Status>
pub fn read_one(&self) -> Result<R, Status>
Attempts to read a single element out of the fifo.
Wraps zx_fifo_read.
Sourcepub fn read_uninit(
&self,
bytes: &mut [MaybeUninit<R>],
) -> Result<&mut [R], Status>
pub fn read_uninit( &self, bytes: &mut [MaybeUninit<R>], ) -> Result<&mut [R], Status>
Attempts to read some number of elements out of the fifo. On success, returns a slice of initialized elements.
Wraps zx_fifo_read.
Sourcepub unsafe fn read_raw(
&self,
buf: *mut R,
count: usize,
) -> Result<usize, Status>
pub unsafe fn read_raw( &self, buf: *mut R, count: usize, ) -> Result<usize, Status>
Attempts to read some number of elements out of the fifo. On success, returns the number of elements actually read.
Wraps zx_fifo_read.
§Safety
The caller is responsible for ensuring bytes
points to valid (albeit
not necessarily initialized) memory at least len
bytes long.
Trait Implementations§
Source§impl<R, W> AsHandleRef for Fifo<R, W>
impl<R, W> AsHandleRef for Fifo<R, W>
Source§fn as_handle_ref(&self) -> Unowned<'_, Handle>
fn as_handle_ref(&self) -> Unowned<'_, Handle>
object_wait_many
.