Expand description
A portable object store that caches plain Rust values on the heap, over pluggable backends from bare-metal to hosted systems.
Objects have a name and a type. They are read from the backend on first use and kept in RAM
within a budget. Changes stay in RAM until you flush them, so the writes to storage only happen
when and where you choose. No function waits: a call that can’t be done now returns Ok(None).
ObjShelf: mounting, the RAM budget, locking, durability, and an example.- Objects:
list,get,insert,get_or_insert_with,remove,withandwith_mut. - Writes:
flushandflush_object. Storage:usageandwear. - Backends:
backend::nor, NOR flash through any blockingNorFlashdriver, andbackend::fs, a directory of files (featurefs).
§Features
fs: the file system backend, for Unix. It needsstd. Without it the crate isno_stdand only needsalloc.
The repository has the README, with timings and a
lifetime estimate for NOR flash, and two examples of a whole app: examples/rtic_nor, RTIC 2
on an STM32F413 with SPI NOR, and examples/std_fs.rs, the same app on std.
Modules§
- backend
- Storage backends: where objects live when they are not in RAM.
Structs§
- Handle
- Typed handle to an object of type
T, obtained fromgetorinsert. - ObjShelf
- Object memory on top of a storage
Backend, shared between RTIC tasks as a#[shared]resource. - Object
Id - Identifier of an object stored in a
backend::Backend.
Enums§
Constants§
- MAX_
NAME_ LEN - Longest name of an object, in bytes of UTF-8. A name is written again with each write of its object, and this keeps it in the first page of the object on NOR flash, so mount reads one page per object to find the names.
Traits§
- Mutex
- The lock trait of RTIC 2 (
rtic::Mutex): the functions of this crate take anything that implements it. Implement it to share anObjShelfwithout RTIC. Memory safe access to shared resources - Storable
- Types that can be kept in an
ObjShelf: serialized when they go to the backend, and measured in RAM withGetSizefrom theget-size2crate (#[derive(GetSize)]).Send, as RTIC shares resources between tasks of different priorities.
Functions§
- flush
- Writes the changes to the backend: the modified and new objects, each with its name, then the
removals. Returns
Ok(None)if another flush has the storage (this one preempted it). - flush_
object - Writes the object of
handleto the backend if it is modified, with its name. The other changes, removals included, stay in RAM untilflush. - get
- Handle to the object
name. - get_
or_ insert_ with - Handle to the object
name. If there is no object with this name (as on the first boot), inserts the value returned byffirst;fonly runs in that case, and it fails asinsertdoes. - insert
- Inserts a new object
nameand returns its handle. The object is in RAM, and reaches the backend at the nextflush. - list
- Names of all the stored objects, in no particular order.
- remove
- Removes the object of
handle. The removal reaches the backend at the nextflush. - usage
- How the backend’s space is used (see
Usage), as of the last storage operation. - wear
- How worn the backend’s storage is (see
Wear), as of the last storage operation.Noneif the backend doesn’t track it: its storage doesn’t wear out, or something else handles it. - with
- Runs
fon the object ofhandleand returns its result. Reads the object if it is not in RAM, or returnsOk(None)without runningfif a flush has the storage (see Not now). - with_
mut - Runs
fon the object ofhandlewith mutable access and returns its result. Reads the object if it is not in RAM. The change is in RAM when this returns, and reaches the backend at the nextflush.