pub struct StorageEngine { /* private fields */ }Expand description
Thread-safe, lazily-initialised storage engine.
The engine owns the ObjectStore adapter and exposes the asset-ingestion
pipeline. It is Send + Sync and designed to be stored in a global
OnceLock so that FFI bindings can access it without constructing their
own instance.
Implementations§
Source§impl StorageEngine
impl StorageEngine
Sourcepub fn from_env() -> StorageResult<Self>
pub fn from_env() -> StorageResult<Self>
Construct the engine from environment variables.
§Environment Variables
| Variable | Used by | Purpose |
|---|---|---|
NAP_STORAGE_BACKEND | both | local (default) or s3 |
NAP_DIR | local | Base directory (default: ~/.nap) |
NAP_S3_BUCKET | s3 | S3 bucket name (required) |
AWS_ACCESS_KEY_ID | s3 | AWS / R2 access key |
AWS_SECRET_ACCESS_KEY | s3 | AWS / R2 secret key |
AWS_REGION | s3 | AWS region (e.g. us-east-1) |
AWS_ENDPOINT_URL_S3 | s3 | Custom S3 endpoint (R2, MinIO) |
AWS_ENDPOINT_URL | s3 | Fallback if AWS_ENDPOINT_URL_S3 unset |
Sourcepub fn config(&self) -> &StorageConfig
pub fn config(&self) -> &StorageConfig
Return the active configuration.
Sourcepub fn store(&self) -> &dyn ObjectStore
pub fn store(&self) -> &dyn ObjectStore
Return a reference to the underlying ObjectStore.
Sourcepub async fn ingest_media(
&self,
data: &[u8],
format: &str,
) -> StorageResult<String>
pub async fn ingest_media( &self, data: &[u8], format: &str, ) -> StorageResult<String>
Ingest media bytes into the content-addressed store.
This is the core ingestion pipeline:
- Hash — Compute
blake3:<hex>from the byte slice. - Idempotency check — Send a HEAD request to see if the blob already exists. If it does, return the hash immediately without any network / disk write.
- PUT — Upload the bytes as
<hex>.<format>under the assets prefix (.nap-assets/for both backends).
§Arguments
data— Raw media bytes (image, audio, mesh, etc.).format— File extension without leading dot (e.g."png","jpg","wav","glb").
§Returns
The content-addressed hash string blake3:<hex>.
Auto Trait Implementations§
impl !RefUnwindSafe for StorageEngine
impl !UnwindSafe for StorageEngine
impl Freeze for StorageEngine
impl Send for StorageEngine
impl Sync for StorageEngine
impl Unpin for StorageEngine
impl UnsafeUnpin for StorageEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request