shelf
Types
pub type ShelfError {
NotFound
KeyAlreadyPresent
TableClosed
NotOwner
FileError(String)
NameConflict
InvalidPath(String)
FileSizeLimitExceeded
TypeMismatch(List(decode.DecodeError))
ErlangError(String)
}
Constructors
-
NotFoundNo value found for the given key
-
KeyAlreadyPresentKey already exists (for insert_new)
-
TableClosedTable has been closed or doesn’t exist
-
NotOwnerThe calling process is not the table owner.
ETS tables are
protected— only the process that calledopen()can perform writes and lifecycle operations. Other processes can read freely. Wrap the table in a supervised actor/server if you need cross-process writes. -
FileError(String)DETS file could not be found or created
-
NameConflictA DETS file at this path is already open by another shelf table. This is a file-level conflict, not related to the table name.
-
InvalidPath(String)The DETS file path is invalid (escapes base directory, contains null bytes, or is otherwise unsafe)
-
FileSizeLimitExceededDETS file exceeds the 2 GB limit
-
TypeMismatch(List(decode.DecodeError))Data loaded from DETS did not match the expected types.
Returned when opening a table whose DETS file contains entries that fail to decode with the provided key/value decoders. The list of
DecodeErrors describes which fields failed and why. -
ErlangError(String)Erlang-level error (catch-all)
Controls when writes are persisted to disk.
pub type WriteMode {
WriteBack
WriteThrough
}
Constructors
-
WriteBackWrites go to ETS only. Call
save()to persist.Best for high-throughput writes where you control the save schedule. Data written since the last
save()is lost on crash. -
WriteThroughEvery write goes to both ETS and DETS immediately.
Slower writes but no data loss between saves. Reads are still fast (always from ETS).
Values
pub fn config(
name name: String,
path path: String,
base_directory base_directory: String,
) -> Config
Create a config with defaults (WriteBack mode).
The name is a diagnostic label for the table — it is not used as an
ETS table name and does not need to be unique. Multiple tables can
share the same name as long as they use different DETS file paths.
The base_directory restricts DETS file paths to prevent directory
traversal attacks. The path is resolved relative to base_directory.
let conf = shelf.config(name: "users", path: "users.dets",
base_directory: "/app/data")