std/storage/memory
std/storage/src/memory.trb
MemoryStorage: the driver of memory:, a table in memory for as long as the driver lives.
type MemoryStorage
shared type MemoryStorage with Storage
memory: - bytes kept in a table for as long as the driver lives, and the double every test of a program that
stores things needs: the same trait as the drivers that reach a disk or a network, with nothing to set up and nothing
to clean away.
A reference is its whole text (memory:/notes/first), and a directory is only a prefix of other references:
memory:/notes exists and lists memory:/notes/first because something is stored below it, and deleting it deletes
everything below it.
Examples
fn remembered(): Task<Result<List<Uri>, StorageFailure>> {
var storage = MemoryStorage()
storage.writeText("memory:/notes/first", "one").await()?
storage.writeText("memory:/notes/second", "two").await()?
storage.list("memory:/notes").await()
}
fn schemes
fn schemes(): List<String>
Always ["memory"].
fn read
fn read(uri: Uri): Task<Result<Bytes, StorageFailure>>
The bytes stored at exactly uri.
Errors
StorageFailure.NotAddressableif the scheme ofuriis notmemory.StorageFailure.NotFoundif nothing is stored aturi; a prefix of stored references is a directory and holds no bytes.
fn exists
fn exists(uri: Uri): Task<Result<Bool, StorageFailure>>
Whether something is stored at uri or below it.
Errors
StorageFailure.NotAddressableif the scheme ofuriis notmemory.
fn list
fn list(uri: Uri): Task<Result<List<Uri>, StorageFailure>>
The references one level below uri, sorted; a deeper reference is listed as its first segment.
Errors
StorageFailure.NotAddressableif the scheme ofuriis notmemory.StorageFailure.NotFoundif nothing is stored at or belowuri.StorageFailure.Refusedif a listed key is no valid reference.
fn write
var fn write(uri: Uri, content: Bytes): Task<Result<Void, StorageFailure>>
Stores content at uri, replacing what was there. This never fails for a memory: reference.
Errors
StorageFailure.NotAddressableif the scheme ofuriis notmemory.
fn delete
var fn delete(uri: Uri): Task<Result<Void, StorageFailure>>
Removes what is stored at uri and everything below it.
Errors
StorageFailure.NotAddressableif the scheme ofuriis notmemory.StorageFailure.NotFoundif nothing is stored at or belowuri.