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§
Sourcefn write_file<D: ReadAt + Sync>(
&self,
data: D,
) -> impl Future<Output = Result<ChunkAddress>> + MaybeSend
fn write_file<D: ReadAt + Sync>( &self, data: D, ) -> impl Future<Output = Result<ChunkAddress>> + MaybeSend
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.
Sourcefn write_encrypted_file<D: ReadAt + Sync>(
&self,
data: D,
) -> impl Future<Output = Result<EncryptedChunkRef>> + MaybeSend
fn write_encrypted_file<D: ReadAt + Sync>( &self, data: D, ) -> impl Future<Output = Result<EncryptedChunkRef>> + MaybeSend
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".