pub struct Writer { /* private fields */ }
Expand description
A reference to an open file writing to the cache.
Implementations
sourceimpl Writer
impl Writer
sourcepub async fn create<P, K>(cache: P, key: K) -> Result<Writer> where
P: AsRef<Path>,
K: AsRef<str>,
pub async fn create<P, K>(cache: P, key: K) -> Result<Writer> where
P: AsRef<Path>,
K: AsRef<str>,
Creates a new writable file handle into the cache.
Example
use async_attributes;
use async_std::prelude::*;
#[async_attributes::main]
async fn main() -> cacache::Result<()> {
let mut fd = cacache::Writer::create("./my-cache", "my-key").await?;
fd.write_all(b"hello world").await.expect("Failed to write to cache");
// Data is not saved into the cache until you commit it.
fd.commit().await?;
Ok(())
}
Trait Implementations
sourceimpl AsyncWrite for Writer
impl AsyncWrite for Writer
sourcefn poll_write(
self: Pin<&mut Self>,
cx: &mut TaskContext<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write(
self: Pin<&mut Self>,
cx: &mut TaskContext<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
Attempt to write bytes from buf
into the object. Read more
sourcefn poll_flush(
self: Pin<&mut Self>,
cx: &mut TaskContext<'_>
) -> Poll<Result<()>>
fn poll_flush(
self: Pin<&mut Self>,
cx: &mut TaskContext<'_>
) -> Poll<Result<()>>
Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
sourcefn poll_close(
self: Pin<&mut Self>,
cx: &mut TaskContext<'_>
) -> Poll<Result<()>>
fn poll_close(
self: Pin<&mut Self>,
cx: &mut TaskContext<'_>
) -> Poll<Result<()>>
Attempt to close the object. Read more
Auto Trait Implementations
impl RefUnwindSafe for Writer
impl Send for Writer
impl Sync for Writer
impl Unpin for Writer
impl UnwindSafe for Writer
Blanket Implementations
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> where
Self: Unpin,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> where
Self: Unpin,
Writes some bytes into the byte stream. Read more
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self> where
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self> where
Self: Unpin,
Like [write()
][AsyncWriteExt::write()
], except that it writes a slice of buffers. Read more
fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self> where
Self: Unpin,
fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self> where
Self: Unpin,
Writes an entire buffer into the byte stream. Read more
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
fn flush(&mut self) -> Flush<'_, Self> where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self> where
Self: Unpin,
Creates a future which will entirely flush this AsyncWrite
. Read more
fn close(&mut self) -> Close<'_, Self> where
Self: Unpin,
fn close(&mut self) -> Close<'_, Self> where
Self: Unpin,
Creates a future which will entirely close this AsyncWrite
.
fn write(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> where
Self: Unpin,
fn write(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> where
Self: Unpin,
Creates a future which will write bytes from buf
into the object. Read more
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self> where
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self> where
Self: Unpin,
Creates a future which will write bytes from bufs
into the object using vectored
IO operations. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> WriteExt for T where
T: AsyncWrite + ?Sized,
impl<T> WriteExt for T where
T: AsyncWrite + ?Sized,
sourcefn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> where
Self: Unpin,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> where
Self: Unpin,
Writes some bytes into the byte stream. Read more
sourcefn flush(&mut self) -> FlushFuture<'_, Self> where
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self> where
Self: Unpin,
Flushes the stream to ensure that all buffered contents reach their destination. Read more