Struct actix_web_lab::extract::ThinData
source · pub struct ThinData<T>(pub T);
Expand description
Application data wrapper and extractor for cheaply-cloned types.
Similar to Actix Web’s Data
wrapper but for Clone
types that are already an Arc
internally
or shares state using some other means when cloned.
Unlike Data
, this wrapper clones T
during extraction. Therefore, it is the user’s
responsibility to ensure that clones of T
do actually share the same state, otherwise state
may be unexpectedly different across multiple requests.
Note that if your type is an Arc<T>
then it’s recommended to use Actix Web’s Data::from(arc)
conversion instead.
§Examples
use actix_web_lab::extract::ThinData;
use actix_web::{App, Responder, HttpResponse, web};
// Use the `ThinData<T>` extractor to access a database connection pool.
async fn index(ThinData(db_pool): ThinData<DbPool>) -> impl Responder {
// database action ...
HttpResponse::Ok()
}
let db_pool = DbPool::default();
App::new()
.app_data(ThinData(db_pool.clone()))
.service(web::resource("/").get(index))
Tuple Fields§
§0: T
Trait Implementations§
source§impl<T: Clone + 'static> FromRequest for ThinData<T>
impl<T: Clone + 'static> FromRequest for ThinData<T>
§type Future = Ready<Result<ThinData<T>, <ThinData<T> as FromRequest>::Error>>
type Future = Ready<Result<ThinData<T>, <ThinData<T> as FromRequest>::Error>>
Future that resolves to a
Self
. Read moresource§fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future
Create a
Self
from request parts asynchronously.Auto Trait Implementations§
impl<T> RefUnwindSafe for ThinData<T>where
T: RefUnwindSafe,
impl<T> Send for ThinData<T>where
T: Send,
impl<T> Sync for ThinData<T>where
T: Sync,
impl<T> Unpin for ThinData<T>where
T: Unpin,
impl<T> UnwindSafe for ThinData<T>where
T: 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, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load
.