Skip to main content

OpenedAsyncWriter

Struct OpenedAsyncWriter 

Source
pub struct OpenedAsyncWriter { /* private fields */ }
Expand description

An already-open asynchronous writer bound to provider identity.

§Examples

use qubit_fs::metadata::{FileKind, FileMetadata, FileSystemId, OpenedFileInfo};
use qubit_fs::path::Path;
use qubit_fs::spi::{AsyncFileWriteSession, OpenedAsyncWriter, SpiFuture};
use qubit_fs::write::{WriteAbortOutcome, WriteFailure};
use qubit_io::AsyncOutput;
use std::io::Result as IoResult;
use std::pin::Pin;
use std::task::{Context, Poll};

struct Session;
impl AsyncOutput for Session {
    type Item = u8;
    unsafe fn poll_write_unchecked(
        self: Pin<&mut Self>,
        _: &mut Context<'_>,
        _: &[u8],
        _: usize,
        count: usize,
    ) -> Poll<IoResult<usize>> {
        Poll::Ready(Ok(count))
    }
    fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<IoResult<()>> {
        Poll::Ready(Ok(()))
    }
}
impl AsyncFileWriteSession for Session {
    fn commit_async<'a>(
        self: Pin<&'a mut Self>,
    ) -> SpiFuture<'a, Result<qubit_fs::metadata::WriteOutcome, WriteFailure>> {
        Box::pin(async { unreachable!() })
    }
    fn abort_async<'a>(self: Pin<&'a mut Self>) -> SpiFuture<'a, qubit_fs::error::FsResult<WriteAbortOutcome>> {
        Box::pin(async { Ok(WriteAbortOutcome::NotPublished) })
    }
}
let info = OpenedFileInfo::new(FileSystemId::new("doc")?, Path::parse("/draft")?)
    .with_metadata(FileMetadata::new(FileKind::File));
let writer = OpenedAsyncWriter::new(info, Box::new(Session));
assert_eq!("/draft", writer.info().path().as_str());

Implementations§

Source§

impl OpenedAsyncWriter

Source

pub fn new( info: OpenedFileInfo, session: Box<dyn AsyncFileWriteSession>, ) -> Self

Wraps an opened provider writer session and its validated identity.

§Parameters
  • info: Identity claimed for the opened resource.
  • session: Provider asynchronous writer session.
§Returns

An opened-writer envelope for facade validation.

Source

pub fn info(&self) -> &OpenedFileInfo

Returns the immutable provider-opened identity.

§Returns

The identity claimed by the provider.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.