pub struct ThinData<T>(pub T);
Expand description
Application data wrapper and extractor for cheaply-cloned types.
Similar to the Data
wrapper but for Clone
/Copy
types that are already an Arc
internally,
share state using some other means when cloned, or is otherwise static data that is very cheap
to clone.
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 literally an Arc<T>
then it’s recommended to use the
Data::from(arc)
conversion instead.
§Examples
use actix_web::{
web::{self, ThinData},
App, HttpResponse, Responder,
};
// 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>
Auto Trait Implementations§
impl<T> Freeze for ThinData<T>where
T: Freeze,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)