Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

The top-level manager for document collections in Cyberpath Sentinel.

Store manages the root directory where all collections are stored. It handles directory creation, collection access, and serves as the entry point for all document storage operations. Each Store instance corresponds to a single filesystem-backed database.

§Architecture

The Store creates a hierarchical structure:

  • Root directory (specified at creation)
    • data/ subdirectory (contains all collections)
      • Collection directories (e.g., users/, audit_logs/)

§Examples

use sentinel_dbms::Store;

// Create a new store at the specified path
let store =
    Store::new("/var/lib/sentinel/db", Some("my_passphrase")).await?;

// Access a collection
let users = store.collection("users").await?;

§Thread Safety

Store is safe to share across threads. Multiple collections can be accessed concurrently, with each collection managing its own locking internally.

Implementations§

Source§

impl Store

Source

pub async fn new<P>(root_path: P, passphrase: Option<&str>) -> Result<Self>
where P: AsRef<Path>,

Creates a new Store instance at the specified root path.

This method initializes the store by creating the root directory if it doesn’t exist. It does not create the data/ subdirectory until collections are accessed.

§Parameters
  • root_path - The filesystem path where the store will be created. This can be any type that implements AsRef<Path>, including &str, String, Path, and PathBuf.
§Returns
  • Result<Self> - Returns a new Store instance on success, or a SentinelError if:
    • The directory cannot be created due to permission issues
    • The path is invalid or cannot be accessed
    • I/O errors occur during directory creation
§Examples
use sentinel_dbms::Store;

// Create a store with a string path
let store = Store::new("/var/lib/sentinel", None).await?;

// Create a store with a PathBuf
use std::path::PathBuf;
let path = PathBuf::from("/tmp/my-store");
let store = Store::new(path, None).await?;

// Create a store in a temporary directory
let temp_dir = std::env::temp_dir().join("sentinel-test");
let store = Store::new(&temp_dir, None).await?;
§Notes
  • If the directory already exists, this method succeeds without modification
  • Parent directories are created automatically if they don’t exist
  • The created directory will have default permissions set by the operating system
Source

pub async fn collection(&self, name: &str) -> Result<Collection>

Retrieves or creates a collection with the specified name.

This method provides access to a named collection within the store. If the collection directory doesn’t exist, it will be created automatically under the data/ subdirectory of the store’s root path.

§Parameters
  • name - The name of the collection. This will be used as the directory name under data/. The name should be filesystem-safe (avoid special characters that are invalid in directory names on your target platform).
§Returns
  • Result<Collection> - Returns a Collection instance on success, or a SentinelError if:
    • The collection directory cannot be created due to permission issues
    • The name contains invalid characters for the filesystem
    • I/O errors occur during directory creation
§Examples
use sentinel_dbms::Store;
use serde_json::json;

let store = Store::new("/var/lib/sentinel", None).await?;

// Access a users collection
let users = store.collection("users").await?;

// Insert a document into the collection
users.insert("user-123", json!({
    "name": "Alice",
    "email": "alice@example.com"
})).await?;

// Access multiple collections
let audit_logs = store.collection("audit_logs").await?;
let certificates = store.collection("certificates").await?;
§Collection Naming

Collection names should follow these guidelines:

  • Use lowercase letters, numbers, underscores, and hyphens
  • Avoid spaces and special characters
  • Keep names descriptive but concise (e.g., users, audit_logs, api_keys)
§Notes
  • Calling this method multiple times with the same name returns separate Collection instances pointing to the same directory
  • The data/ subdirectory is created automatically on first collection access
  • Collections are not cached; each call creates a new Collection instance
  • No validation is performed on the collection name beyond filesystem constraints
Source

pub fn set_signing_key(&mut self, key: SigningKey)

Trait Implementations§

Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnwindSafe for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more