Skip to main content

ChunkPutExt

Trait ChunkPutExt 

Source
pub trait ChunkPutExt<const BODY_SIZE: usize>: ChunkPut<BODY_SIZE> {
    // Provided methods
    fn write_file<D: ReadAt + Sync>(
        &self,
        data: D,
    ) -> impl Future<Output = Result<ChunkAddress>> + MaybeSend
       where Self: Sized + MaybeSync { ... }
    fn write_encrypted_file<D: ReadAt + Sync>(
        &self,
        data: D,
    ) -> impl Future<Output = Result<EncryptedChunkRef>> + MaybeSend
       where Self: Sized + MaybeSync { ... }
}
Expand description

Extension methods for chunk putters.

Splits data on rayon, then stores the chunks via the async ChunkPut. Uses JoinRef for unified plain/encrypted dispatch on read-back.

use futures::executor::block_on;
use nectar_primitives::file::{ChunkGetExt, ChunkPutExt};
use nectar_primitives::store::MemoryStore;
use nectar_primitives::DEFAULT_BODY_SIZE;

let store = MemoryStore::<DEFAULT_BODY_SIZE>::new();
let addr = block_on(store.write_file(b"hello swarm".to_vec())).unwrap();
let recovered = block_on(store.read_file(addr)).unwrap();
assert_eq!(recovered, b"hello swarm");

Provided Methods§

Source

fn write_file<D: ReadAt + Sync>( &self, data: D, ) -> impl Future<Output = Result<ChunkAddress>> + MaybeSend
where Self: Sized + MaybeSync,

Split data and store every produced chunk, returning the root address.

Splitting runs on rayon up front; data is dropped before the first store await, so the returned future never holds the source.

Source

fn write_encrypted_file<D: ReadAt + Sync>( &self, data: D, ) -> impl Future<Output = Result<EncryptedChunkRef>> + MaybeSend
where Self: Sized + MaybeSync,

Split data into encrypted chunks and store them, returning the root reference.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<T, const BODY_SIZE: usize> ChunkPutExt<BODY_SIZE> for T
where T: ChunkPut<BODY_SIZE>,