pub struct WasiMemoryProvider { /* private fields */ }Expand description
File-backed MemoryProvider for WASI runtimes.
Persists database pages as a single flat file on the filesystem. Each page is 64 KiB, matching the WASM memory page size. The file layout is byte-for-byte equivalent to IC stable memory, enabling portable database snapshots.
Single-writer access is the caller’s responsibility. WASM is single-threaded by default and WASI lock support varies across runtimes.
§Examples
use wasi_dbms_memory::WasiMemoryProvider;
use wasm_dbms_memory::MemoryProvider;
let mut provider = WasiMemoryProvider::new("./data/mydb.bin").unwrap();
provider.grow(1).unwrap(); // allocate 1 page (64 KiB)
let data = b"hello";
provider.write(0, data).unwrap();
let mut buf = vec![0u8; 5];
provider.read(0, &mut buf).unwrap();
assert_eq!(&buf, data);Implementations§
Source§impl WasiMemoryProvider
impl WasiMemoryProvider
Sourcepub fn new(path: impl AsRef<Path>) -> MemoryResult<Self>
pub fn new(path: impl AsRef<Path>) -> MemoryResult<Self>
Opens or creates a file-backed memory provider at path.
If the file exists, the page count is inferred from the file size. If the file does not exist, it is created empty (0 pages).
§Errors
Returns MemoryError::ProviderError if:
- The file cannot be opened or created.
- The existing file size is not a multiple of the page size (64 KiB).
Trait Implementations§
Source§impl Debug for WasiMemoryProvider
impl Debug for WasiMemoryProvider
Source§impl MemoryProvider for WasiMemoryProvider
impl MemoryProvider for WasiMemoryProvider
Source§impl TryFrom<&Path> for WasiMemoryProvider
impl TryFrom<&Path> for WasiMemoryProvider
Auto Trait Implementations§
impl Freeze for WasiMemoryProvider
impl RefUnwindSafe for WasiMemoryProvider
impl Send for WasiMemoryProvider
impl Sync for WasiMemoryProvider
impl Unpin for WasiMemoryProvider
impl UnsafeUnpin for WasiMemoryProvider
impl UnwindSafe for WasiMemoryProvider
Blanket Implementations§
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
Mutably borrows from an owned value. Read more