Skip to main content

SyncChunkPutExt

Trait SyncChunkPutExt 

Source
pub trait SyncChunkPutExt<const BODY_SIZE: usize>: SyncChunkPut<BODY_SIZE> {
    // Provided methods
    fn writer(&self, size: u64) -> SyncSplitter<&Self, BODY_SIZE>
       where Self: Sized { ... }
    fn encrypted_writer(
        &self,
        size: u64,
    ) -> EncryptedSyncSplitter<&Self, BODY_SIZE>
       where Self: Sized { ... }
    fn write_file(&self, data: &[u8]) -> Result<ChunkAddress>
       where Self: Send + Sync + Sized { ... }
    fn write_encrypted_file(&self, data: &[u8]) -> Result<EncryptedChunkRef>
       where Self: Send + Sync + Sized { ... }
}
Expand description

Extension methods for sync chunk putters.

Automatically implemented for all types that implement SyncChunkPut.

use nectar_primitives::file::{SyncChunkPutExt, SyncChunkGetExt};
use nectar_primitives::store::MemoryStore;
use nectar_primitives::DEFAULT_BODY_SIZE;
use std::io::Write;

// Filesystem-style write/read
let store = MemoryStore::<DEFAULT_BODY_SIZE>::new();
let addr = store.write_file(b"hello").unwrap();

// Streaming write via std::io::Write
let mut writer = store.writer(6);
writer.write_all(b"world!").unwrap();
let (root, _) = writer.finish().unwrap();

Provided Methods§

Source

fn writer(&self, size: u64) -> SyncSplitter<&Self, BODY_SIZE>
where Self: Sized,

Create a writer for streaming data. Returns a SyncSplitter implementing Write. Call .finish() on the returned writer to get the root address.

Source

fn encrypted_writer(&self, size: u64) -> EncryptedSyncSplitter<&Self, BODY_SIZE>
where Self: Sized,

Create an encrypted writer. Returns an EncryptedSyncSplitter implementing Write.

Source

fn write_file(&self, data: &[u8]) -> Result<ChunkAddress>
where Self: Send + Sync + Sized,

Write file data into the store (like fs::write).

Source

fn write_encrypted_file(&self, data: &[u8]) -> Result<EncryptedChunkRef>
where Self: Send + Sync + Sized,

Write encrypted file data into the store.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, const BODY_SIZE: usize> SyncChunkPutExt<BODY_SIZE> for T
where T: SyncChunkPut<BODY_SIZE>,