pub struct ProjectContext<S: BootstrapPhase = Initialized> { /* private fields */ }Expand description
Shared context and configs for all apps. Used in conjunction with the
Project trait.
Implementations§
Source§impl<S: BootstrapPhase<Config = Arc<ProjectConfig>>> ProjectContext<S>
impl<S: BootstrapPhase<Config = Arc<ProjectConfig>>> ProjectContext<S>
Sourcepub fn config(&self) -> &ProjectConfig
pub fn config(&self) -> &ProjectConfig
Returns the configuration for the project.
§Examples
use cot::request::{Request, RequestExt};
use cot::response::Response;
async fn index(request: Request) -> cot::Result<Response> {
let config = request.context().config();
// can also be accessed via:
let config = request.project_config();
let db_url = &config.database.url;
// ...
}Source§impl<S: BootstrapPhase<Apps = Vec<Box<dyn App>>>> ProjectContext<S>
impl<S: BootstrapPhase<Apps = Vec<Box<dyn App>>>> ProjectContext<S>
Source§impl<S: BootstrapPhase<Router = Arc<Router>>> ProjectContext<S>
impl<S: BootstrapPhase<Router = Arc<Router>>> ProjectContext<S>
Sourcepub fn router(&self) -> &Arc<Router>
pub fn router(&self) -> &Arc<Router>
Returns the router for the project.
§Examples
use cot::request::{Request, RequestExt};
use cot::response::Response;
async fn index(request: Request) -> cot::Result<Response> {
let router = request.context().config();
// can also be accessed via:
let router = request.router();
let num_routes = router.routes().len();
// ...
}Source§impl<S: BootstrapPhase<AuthBackend = Arc<dyn AuthBackend>>> ProjectContext<S>
impl<S: BootstrapPhase<AuthBackend = Arc<dyn AuthBackend>>> ProjectContext<S>
Sourcepub fn auth_backend(&self) -> &Arc<dyn AuthBackend>
pub fn auth_backend(&self) -> &Arc<dyn AuthBackend>
Returns the authentication backend for the project.
§Examples
use cot::request::{Request, RequestExt};
use cot::response::Response;
async fn index(request: Request) -> cot::Result<Response> {
let auth_backend = request.context().auth_backend();
// ...
}Source§impl<S: BootstrapPhase<Email = Email>> ProjectContext<S>
impl<S: BootstrapPhase<Email = Email>> ProjectContext<S>
Sourcepub fn email(&self) -> &Email
Available on crate feature email only.
pub fn email(&self) -> &Email
email only.Returns the email service for the project.
§Examples
use cot::request::{Request, RequestExt};
use cot::response::Response;
async fn index(request: Request) -> cot::Result<Response> {
let email = request.context().email();
// ...
}Source§impl<S: BootstrapPhase<Cache = Cache>> ProjectContext<S>
impl<S: BootstrapPhase<Cache = Cache>> ProjectContext<S>
Source§impl<S: BootstrapPhase<Database = Option<Database>>> ProjectContext<S>
impl<S: BootstrapPhase<Database = Option<Database>>> ProjectContext<S>
Sourcepub fn try_database(&self) -> Option<&Database>
Available on crate feature db only.
pub fn try_database(&self) -> Option<&Database>
db only.Returns the database for the project, if it is enabled.
§Examples
use cot::request::{Request, RequestExt};
use cot::response::Response;
async fn index(request: Request) -> cot::Result<Response> {
let database = request.context().try_database();
if let Some(database) = database {
// do something with the database
} else {
// database is not enabled
}
}Sourcepub fn database(&self) -> &Database
Available on crate feature db only.
pub fn database(&self) -> &Database
db only.Returns the database for the project, if it is enabled.
§Panics
This method panics if the database is not enabled.
§Examples
use cot::request::{Request, RequestExt};
use cot::response::Response;
async fn index(request: Request) -> cot::Result<Response> {
let database = request.context().database();
// use the database
}Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for ProjectContext<S>where
<S as BootstrapPhase>::Config: Freeze,
<S as BootstrapPhase>::Apps: Freeze,
<S as BootstrapPhase>::Router: Freeze,
<S as BootstrapPhase>::Database: Freeze,
<S as BootstrapPhase>::AuthBackend: Freeze,
<S as BootstrapPhase>::Cache: Freeze,
<S as BootstrapPhase>::Email: Freeze,
impl<S> RefUnwindSafe for ProjectContext<S>where
<S as BootstrapPhase>::Config: RefUnwindSafe,
<S as BootstrapPhase>::Apps: RefUnwindSafe,
<S as BootstrapPhase>::Router: RefUnwindSafe,
<S as BootstrapPhase>::Database: RefUnwindSafe,
<S as BootstrapPhase>::AuthBackend: RefUnwindSafe,
<S as BootstrapPhase>::Cache: RefUnwindSafe,
<S as BootstrapPhase>::Email: RefUnwindSafe,
impl<S> Send for ProjectContext<S>where
<S as BootstrapPhase>::Config: Send,
<S as BootstrapPhase>::Apps: Send,
<S as BootstrapPhase>::Router: Send,
<S as BootstrapPhase>::Database: Send,
<S as BootstrapPhase>::AuthBackend: Send,
<S as BootstrapPhase>::Cache: Send,
<S as BootstrapPhase>::Email: Send,
impl<S> Sync for ProjectContext<S>where
<S as BootstrapPhase>::Config: Sync,
<S as BootstrapPhase>::Apps: Sync,
<S as BootstrapPhase>::Router: Sync,
<S as BootstrapPhase>::Database: Sync,
<S as BootstrapPhase>::AuthBackend: Sync,
<S as BootstrapPhase>::Cache: Sync,
<S as BootstrapPhase>::Email: Sync,
impl<S> Unpin for ProjectContext<S>where
<S as BootstrapPhase>::Config: Unpin,
<S as BootstrapPhase>::Apps: Unpin,
<S as BootstrapPhase>::Router: Unpin,
<S as BootstrapPhase>::Database: Unpin,
<S as BootstrapPhase>::AuthBackend: Unpin,
<S as BootstrapPhase>::Cache: Unpin,
<S as BootstrapPhase>::Email: Unpin,
impl<S> UnwindSafe for ProjectContext<S>where
<S as BootstrapPhase>::Config: UnwindSafe,
<S as BootstrapPhase>::Apps: UnwindSafe,
<S as BootstrapPhase>::Router: UnwindSafe,
<S as BootstrapPhase>::Database: UnwindSafe,
<S as BootstrapPhase>::AuthBackend: UnwindSafe,
<S as BootstrapPhase>::Cache: UnwindSafe,
<S as BootstrapPhase>::Email: UnwindSafe,
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
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> IntoField<Auto<T>> for T
impl<T> IntoField<Auto<T>> for T
Source§fn into_field(self) -> Auto<T>
fn into_field(self) -> Auto<T>
Available on crate feature
db only.Converts the type to the field type.