pub struct StableIO<M: StableMemory = CanisterStableMemory> { /* private fields */ }api::stable module has been moved to stable (crate root).Expand description
Performs generic IO (read, write, and seek) on stable memory.
Warning: When using write functionality, this will overwrite any existing
data in stable memory as it writes, so ensure you set the offset value
accordingly if you wish to preserve existing data.
Will attempt to grow the memory as it writes, and keep offsets and total capacity.
Implementationsยง
Sourceยงimpl<M: StableMemory> StableIO<M>
impl<M: StableMemory> StableIO<M>
Sourcepub fn with_memory(memory: M, offset: u64) -> Self
๐Deprecated since 0.18.0: The api::stable module has been moved to stable (crate root).
pub fn with_memory(memory: M, offset: u64) -> Self
api::stable module has been moved to stable (crate root).Creates a new StableIO which writes to the selected memory
Sourcepub fn offset(&self) -> u64
๐Deprecated since 0.18.0: The api::stable module has been moved to stable (crate root).
pub fn offset(&self) -> u64
api::stable module has been moved to stable (crate root).Returns the offset of the writer
Sourcepub fn grow(&mut self, new_pages: u64) -> Result<(), StableMemoryError>
๐Deprecated since 0.18.0: The api::stable module has been moved to stable (crate root).
pub fn grow(&mut self, new_pages: u64) -> Result<(), StableMemoryError>
api::stable module has been moved to stable (crate root).Attempts to grow the memory by adding new pages.
Sourcepub fn write(&mut self, buf: &[u8]) -> Result<usize, StableMemoryError>
๐Deprecated since 0.18.0: The api::stable module has been moved to stable (crate root).
pub fn write(&mut self, buf: &[u8]) -> Result<usize, StableMemoryError>
api::stable module has been moved to stable (crate root).Writes a byte slice to the buffer.
ยงErrors
When it cannot grow the memory to accommodate the new data.
Sourcepub fn read(&mut self, buf: &mut [u8]) -> Result<usize, StableMemoryError>
๐Deprecated since 0.18.0: The api::stable module has been moved to stable (crate root).
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize, StableMemoryError>
api::stable module has been moved to stable (crate root).Reads data from the stable memory location specified by an offset.
ยงErrors
The stable memory size is cached on creation of the StableReader.
Therefore, in following scenario, it will get an OutOfBounds error:
- Create a
StableReader - Write some data to the stable memory which causes it grow
- call
read()to read the newly written bytes
Trait Implementationsยง
Sourceยงimpl<M: StableMemory> From<StableIO<M>> for StableReader<M>
impl<M: StableMemory> From<StableIO<M>> for StableReader<M>
Sourceยงimpl<M: StableMemory> From<StableIO<M>> for StableWriter<M>
impl<M: StableMemory> From<StableIO<M>> for StableWriter<M>
Sourceยงimpl<M: StableMemory> Read for StableIO<M>
impl<M: StableMemory> Read for StableIO<M>
Sourceยงfn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
1.36.0 ยท Sourceยงfn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSourceยงfn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 ยท Sourceยงfn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 ยท Sourceยงfn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 ยท Sourceยงfn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSourceยงfn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Sourceยงfn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 ยท Sourceยงfn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read moreSourceยงimpl<M: StableMemory> Seek for StableIO<M>
impl<M: StableMemory> Seek for StableIO<M>
Sourceยงfn seek(&mut self, offset: SeekFrom) -> Result<u64>
fn seek(&mut self, offset: SeekFrom) -> Result<u64>
1.55.0 ยท Sourceยงfn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Sourceยงfn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)Sourceยงimpl<M: StableMemory> Write for StableIO<M>
impl<M: StableMemory> Write for StableIO<M>
Sourceยงfn write(&mut self, buf: &[u8]) -> Result<usize, Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Sourceยงfn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
Sourceยงfn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 ยท Sourceยงfn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Sourceยงfn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Auto Trait Implementationsยง
impl<M> Freeze for StableIO<M>where
M: Freeze,
impl<M> RefUnwindSafe for StableIO<M>where
M: RefUnwindSafe,
impl<M> Send for StableIO<M>where
M: Send,
impl<M> Sync for StableIO<M>where
M: Sync,
impl<M> Unpin for StableIO<M>where
M: Unpin,
impl<M> UnwindSafe for StableIO<M>where
M: UnwindSafe,
Blanket Implementationsยง
Sourceยงimpl<R> BinReaderExt for R
impl<R> BinReaderExt for R
Sourceยงfn read_type<T>(&mut self, endian: Endian) -> Result<T, Error>where
T: BinRead,
fn read_type<T>(&mut self, endian: Endian) -> Result<T, Error>where
T: BinRead,
Sourceยงfn read_be<T>(&mut self) -> Result<T, Error>where
T: BinRead,
fn read_be<T>(&mut self) -> Result<T, Error>where
T: BinRead,
Sourceยงfn read_le<T>(&mut self) -> Result<T, Error>where
T: BinRead,
fn read_le<T>(&mut self) -> Result<T, Error>where
T: BinRead,
Sourceยงfn read_ne<T>(&mut self) -> Result<T, Error>where
T: BinRead,
fn read_ne<T>(&mut self) -> Result<T, Error>where
T: BinRead,
Sourceยงfn read_type_args<T>(
&mut self,
endian: Endian,
args: <T as BinRead>::Args,
) -> Result<T, Error>where
T: BinRead,
fn read_type_args<T>(
&mut self,
endian: Endian,
args: <T as BinRead>::Args,
) -> Result<T, Error>where
T: BinRead,
T from the reader with the given byte order and arguments.Sourceยงfn read_be_args<T>(&mut self, args: <T as BinRead>::Args) -> Result<T, Error>where
T: BinRead,
fn read_be_args<T>(&mut self, args: <T as BinRead>::Args) -> Result<T, Error>where
T: BinRead,
T from the reader, assuming big-endian byte order, using the
given arguments.Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<R> ReadBytesExt for R
impl<R> ReadBytesExt for R
Sourceยงfn read_u8(&mut self) -> Result<u8, Error>
fn read_u8(&mut self) -> Result<u8, Error>
Sourceยงfn read_i8(&mut self) -> Result<i8, Error>
fn read_i8(&mut self) -> Result<i8, Error>
Sourceยงfn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
Sourceยงfn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
Sourceยงfn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
Sourceยงfn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
Sourceยงfn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
Sourceยงfn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
Sourceยงfn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
Sourceยงfn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
Sourceยงfn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
Sourceยงfn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
Sourceยงfn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
Sourceยงfn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
Sourceยงfn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
Sourceยงfn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
Sourceยงfn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
Sourceยงfn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
Sourceยงfn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
Sourceยงfn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
Sourceยงfn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
Sourceยงfn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
Sourceยงfn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
Sourceยงfn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
Sourceยงfn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
Sourceยงfn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
Sourceยงfn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
Sourceยงfn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
Sourceยงfn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
Sourceยงfn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
Sourceยงfn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
read_f32_into instead