pub struct TenantMiddleware { /* private fields */ }Expand description
Middleware that automatically applies tenant filtering to queries.
Implementations§
Source§impl TenantMiddleware
impl TenantMiddleware
Sourcepub fn new(config: TenantConfig) -> Self
pub fn new(config: TenantConfig) -> Self
Create a new tenant middleware with the given config.
Sourcepub fn set_tenant(&self, ctx: TenantContext)
pub fn set_tenant(&self, ctx: TenantContext)
Set the current tenant context.
This writes a process-wide slot shared by every clone of this
middleware, so concurrent requests would overwrite each other’s
tenant. It is a single-threaded escape hatch — prefer
task_local::with_tenant, which this middleware resolves per query
before falling back to this slot.
Sourcepub fn clear_tenant(&self)
pub fn clear_tenant(&self)
Clear the current tenant context.
Sourcepub fn current_tenant(&self) -> Option<TenantContext>
pub fn current_tenant(&self) -> Option<TenantContext>
Get the current tenant context.
Sourcepub fn scoped(&self, ctx: TenantContext) -> TenantScope
pub fn scoped(&self, ctx: TenantContext) -> TenantScope
Create a scoped tenant context (automatically clears on drop).
Trait Implementations§
Source§impl Clone for TenantMiddleware
impl Clone for TenantMiddleware
Source§impl Debug for TenantMiddleware
impl Debug for TenantMiddleware
Source§impl Middleware for TenantMiddleware
impl Middleware for TenantMiddleware
Source§fn handle<'a>(
&'a self,
ctx: QueryContext,
next: Next<'a>,
) -> BoxFuture<'a, QueryResult<QueryResponse>>
fn handle<'a>( &'a self, ctx: QueryContext, next: Next<'a>, ) -> BoxFuture<'a, QueryResult<QueryResponse>>
Handle a query, optionally calling the next handler.
Auto Trait Implementations§
impl !RefUnwindSafe for TenantMiddleware
impl !UnwindSafe for TenantMiddleware
impl Freeze for TenantMiddleware
impl Send for TenantMiddleware
impl Sync for TenantMiddleware
impl Unpin for TenantMiddleware
impl UnsafeUnpin for TenantMiddleware
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