Type Alias FutureWriter

Source
pub type FutureWriter<F> = OperatorFuture<WriteOptions, Writer, F>;
Expand description

Future that generated by Operator::writer_with.

Users can add more options by public functions provided by this struct.

Aliased Type§

struct FutureWriter<F> { /* private fields */ }

Implementations§

Source§

impl<F: Future<Output = Result<Writer>>> FutureWriter<F>

Source

pub fn append(self, v: bool) -> Self

Sets append mode for this write request.

Refer to options::WriteOptions::append for more details.

§Example
use bytes::Bytes;

let mut w = op.writer_with("path/to/file").append(true).await?;
w.write(vec![0; 4096]).await?;
w.write(vec![1; 4096]).await?;
w.close().await?;
Source

pub fn chunk(self, v: usize) -> Self

Sets chunk size for buffered writes.

Refer to options::WriteOptions::chunk for more details.

§Example
use bytes::Bytes;

// Set 8MiB chunk size - data will be sent in one API call at close
let mut w = op
    .writer_with("path/to/file")
    .chunk(8 * 1024 * 1024)
    .await?;
w.write(vec![0; 4096]).await?;
w.write(vec![1; 4096]).await?;
w.close().await?;
Source

pub fn concurrent(self, v: usize) -> Self

Sets concurrent write operations for this writer.

Refer to options::WriteOptions::concurrent for more details.

§Example
use bytes::Bytes;

// Enable concurrent writes with 8 parallel operations
let mut w = op.writer_with("path/to/file").concurrent(8).await?;

// First write starts immediately
w.write(vec![0; 4096]).await?;

// Second write runs concurrently with first
w.write(vec![1; 4096]).await?;

// Ensures all writes complete successfully and in order
w.close().await?;
Source

pub fn cache_control(self, v: &str) -> Self

Sets Cache-Control header for this write operation.

Refer to options::WriteOptions::cache_control for more details.

§Example
use bytes::Bytes;

// Cache content for 7 days (604800 seconds)
let mut w = op
    .writer_with("path/to/file")
    .cache_control("max-age=604800")
    .await?;
w.write(vec![0; 4096]).await?;
w.write(vec![1; 4096]).await?;
w.close().await?;
Source

pub fn content_type(self, v: &str) -> Self

Sets Content-Type header for this write operation.

Refer to options::WriteOptions::content_type for more details.

§Example
use bytes::Bytes;

// Set content type for plain text file
let mut w = op
    .writer_with("path/to/file")
    .content_type("text/plain")
    .await?;
w.write(vec![0; 4096]).await?;
w.write(vec![1; 4096]).await?;
w.close().await?;
Source

pub fn content_disposition(self, v: &str) -> Self

Sets Content-Disposition header for this write request.

Refer to options::WriteOptions::content_disposition for more details.

§Example
use bytes::Bytes;

let mut w = op
    .writer_with("path/to/file")
    .content_disposition("attachment; filename=\"filename.jpg\"")
    .await?;
w.write(vec![0; 4096]).await?;
w.write(vec![1; 4096]).await?;
w.close().await?;
Source

pub fn content_encoding(self, v: &str) -> Self

Sets Content-Encoding header for this write request.

Refer to options::WriteOptions::content_encoding for more details.

§Example
use bytes::Bytes;

let mut w = op
    .writer_with("path/to/file")
    .content_encoding("gzip")
    .await?;
w.write(vec![0; 4096]).await?;
w.write(vec![1; 4096]).await?;
w.close().await?;
Source

pub fn if_match(self, s: &str) -> Self

Sets If-Match header for this write request.

Refer to options::WriteOptions::if_match for more details.

§Behavior
  • If supported, the write operation will only succeed if the target’s ETag matches the specified value
  • The value should be a valid ETag string
  • Common values include:
    • A specific ETag value like "686897696a7c876b7e"
    • * - Matches any existing resource
  • If not supported, the value will be ignored

This operation provides conditional write functionality based on ETag matching, helping prevent unintended overwrites in concurrent scenarios.

§Example
use bytes::Bytes;

let mut w = op
    .writer_with("path/to/file")
    .if_match("\"686897696a7c876b7e\"")
    .await?;
w.write(vec![0; 4096]).await?;
w.write(vec![1; 4096]).await?;
w.close().await?;
Source

pub fn if_none_match(self, s: &str) -> Self

Sets If-None-Match header for this write request.

Refer to options::WriteOptions::if_none_match for more details.

§Example
use bytes::Bytes;

let mut w = op
    .writer_with("path/to/file")
    .if_none_match("\"686897696a7c876b7e\"")
    .await?;
w.write(vec![0; 4096]).await?;
w.write(vec![1; 4096]).await?;
w.close().await?;
Source

pub fn if_not_exists(self, b: bool) -> Self

Sets the condition that write operation will succeed only if target does not exist.

Refer to options::WriteOptions::if_not_exists for more details.

§Example
use bytes::Bytes;

let mut w = op
    .writer_with("path/to/file")
    .if_not_exists(true)
    .await?;
w.write(vec![0; 4096]).await?;
w.write(vec![1; 4096]).await?;
w.close().await?;
Source

pub fn user_metadata( self, data: impl IntoIterator<Item = (String, String)>, ) -> Self

Sets user metadata for this write request.

Refer to options::WriteOptions::user_metadata for more details.

§Example
use bytes::Bytes;

let mut w = op
    .writer_with("path/to/file")
    .user_metadata([
        ("content-type".to_string(), "text/plain".to_string()),
        ("author".to_string(), "OpenDAL".to_string()),
    ])
    .await?;
w.write(vec![0; 4096]).await?;
w.close().await?;