pub struct TrustedDocumentStore { /* private fields */ }Expand description
Trusted document lookup store.
Backed by a DashMap: lookups on the request hot path take only a
per-shard read lock, never an async lock, and hot-reload (the only writer)
replaces entries in place without blocking concurrent readers on other
shards.
Implementations§
Source§impl TrustedDocumentStore
impl TrustedDocumentStore
Sourcepub fn from_manifest_file(
path: &Path,
mode: TrustedDocumentMode,
) -> Result<Self, TrustedDocumentError>
pub fn from_manifest_file( path: &Path, mode: TrustedDocumentMode, ) -> Result<Self, TrustedDocumentError>
Load from a JSON manifest file at startup.
§Errors
Returns an error if the file cannot be read or parsed.
Sourcepub fn from_documents(
documents: HashMap<String, String>,
mode: TrustedDocumentMode,
) -> Self
pub fn from_documents( documents: HashMap<String, String>, mode: TrustedDocumentMode, ) -> Self
Create an in-memory store from a pre-built document map (for testing).
Sourcepub fn disabled() -> Self
pub fn disabled() -> Self
A disabled store that passes all queries through (permissive, empty).
Sourcepub const fn mode(&self) -> TrustedDocumentMode
pub const fn mode(&self) -> TrustedDocumentMode
Returns the enforcement mode.
Sourcepub fn document_count(&self) -> usize
pub fn document_count(&self) -> usize
Returns the number of documents in the manifest.
Sourcepub fn replace_documents(&self, documents: HashMap<String, String>)
pub fn replace_documents(&self, documents: HashMap<String, String>)
Replace the document map (used by hot-reload).
The swap is per-shard atomic — readers may observe the old or the new contents but never a torn entry. Brief inconsistency across shards during a reload is acceptable: a request that resolves a document that has just been removed will simply 404 and the client will retry.
Sourcepub fn resolve(
&self,
document_id: Option<&str>,
raw_query: Option<&str>,
) -> Result<String, TrustedDocumentError>
pub fn resolve( &self, document_id: Option<&str>, raw_query: Option<&str>, ) -> Result<String, TrustedDocumentError>
Resolve a query from document_id and/or raw_query.
document_idpresent + found → return stored query body.document_idpresent + NOT found →DocumentNotFound.- No
document_idin strict mode →ForbiddenRawQuery. - No
document_idin permissive mode → returnraw_query.
§Errors
Returns TrustedDocumentError::DocumentNotFound if a document_id is given but not in the
store. Returns TrustedDocumentError::ForbiddenRawQuery if no document_id is provided
in strict mode, or if raw_query is also absent in permissive mode.
Auto Trait Implementations§
impl !RefUnwindSafe for TrustedDocumentStore
impl !UnwindSafe for TrustedDocumentStore
impl Freeze for TrustedDocumentStore
impl Send for TrustedDocumentStore
impl Sync for TrustedDocumentStore
impl Unpin for TrustedDocumentStore
impl UnsafeUnpin for TrustedDocumentStore
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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>
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>
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 more