std/storage
Bytes at a reference, wherever the scheme of the reference reaches (docs/design/URI.md section 11). Storage is the
capability - read, exists, list, write, delete - and a driver is a shared type that has it for its schemes:
FileStorage for file: over std/fs, and MemoryStorage for memory:, the double every test of a program that
stores things needs. S3, WebDAV and the rest are packages of their own, whose drivers have the same trait.
The program names its drivers, and nothing registers itself. Storage.registry is one storage over several
drivers, chosen by the scheme of each reference it is handed, and a scheme it was not given is a failure that lists
the ones it was:
use Storage, StorageFailure, FileStorage, MemoryStorage from "std/storage"
fn stored(): Task<Result<String, StorageFailure>> {
var storage = Storage.registry([FileStorage(), MemoryStorage()])
storage.writeText("memory:/notes/first", "hello").await()?
storage.readText("memory:/notes/first").await()
}
A reference is a Uri, so a relative one has no scheme to choose a driver by and is resolved against a base first
(reference.resolved(against: base)). Every failure carries the reference as show() wrote it, so a password in a
reference never reaches a log through a failure.
Modules
std/storage/file[FileStorage]: the driver offile:, overstd/fs.std/storage/memory[MemoryStorage]: the driver ofmemory:, a table in memory for as long as the driver lives.std/storage/storage[Storage], the capability, [StorageFailure], what a storage refuses with, and the registryStorage.registryanswers: one storage over several drivers, itself a storage.
Everything
- type
FileStoragefile:- the local disk, throughstd/fs. - type
MemoryStoragememory:- 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. - trait
StorageBytes at a reference, wherever the scheme reaches: five members every driver writes, and two over them. - type
StorageFailureWhat a storage refuses with.