Skip to main content

Crate objshelf

Crate objshelf 

Source
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).

§Features

  • fs: the file system backend, for Unix. It needs std. Without it the crate is no_std and only needs alloc.

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 from get or insert.
ObjShelf
Object memory on top of a storage Backend, shared between RTIC tasks as a #[shared] resource.
ObjectId
Identifier of an object stored in a backend::Backend.

Enums§

Error
Errors of ObjShelf, generic over the backend’s error E.

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 an ObjShelf without 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 with GetSize from the get-size2 crate (#[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 handle to the backend if it is modified, with its name. The other changes, removals included, stay in RAM until flush.
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 by f first; f only runs in that case, and it fails as insert does.
insert
Inserts a new object name and returns its handle. The object is in RAM, and reaches the backend at the next flush.
list
Names of all the stored objects, in no particular order.
remove
Removes the object of handle. The removal reaches the backend at the next flush.
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. None if the backend doesn’t track it: its storage doesn’t wear out, or something else handles it.
with
Runs f on the object of handle and returns its result. Reads the object if it is not in RAM, or returns Ok(None) without running f if a flush has the storage (see Not now).
with_mut
Runs f on the object of handle with 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 next flush.