From be10425d25c56d8a4c08595ecbfea09824e57b5a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 9 Oct 2020 13:51:48 +0200 Subject: [PATCH] Improve docs for Data extractor --- src/data.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/data.rs b/src/data.rs index 6405fd901..d5923161f 100644 --- a/src/data.rs +++ b/src/data.rs @@ -19,12 +19,11 @@ pub(crate) type FnDataFactory = /// Application data. /// -/// Application data is an arbitrary data attached to the app. -/// Application data is available to all routes and could be added -/// during application configuration process -/// with `App::data()` method. +/// Application data is a piece of arbitrary data attached to the app. +/// Application data is available to all routes and can be added +/// during the application configuration process via `App::data()`. /// -/// Application data could be accessed by using `Data` +/// Application data can be accessed by using `Data` /// extractor where `T` is data type. /// /// **Note**: http server accepts an application factory rather than @@ -32,9 +31,7 @@ pub(crate) type FnDataFactory = /// instance for each thread, thus application data must be constructed /// multiple times. If you want to share data between different /// threads, a shareable object should be used, e.g. `Send + Sync`. Application -/// data does not need to be `Send` or `Sync`. Internally `Data` type -/// uses `Arc`. if your data implements `Send` + `Sync` traits you can -/// use `web::Data::new()` and avoid double `Arc`. +/// data does not need to be `Send` or `Sync`. Internally `Data` uses `Arc`. /// /// If route data is not set for a handler, using `Data` extractor would /// cause *Internal Server Error* response. @@ -47,7 +44,7 @@ pub(crate) type FnDataFactory = /// counter: usize, /// } /// -/// /// Use `Data` extractor to access data in handler. +/// /// Use the `Data` extractor to access data in a handler. /// async fn index(data: web::Data>) -> impl Responder { /// let mut data = data.lock().unwrap(); /// data.counter += 1; @@ -70,10 +67,6 @@ pub struct Data(Arc); impl Data { /// Create new `Data` instance. - /// - /// Internally `Data` type uses `Arc`. if your data implements - /// `Send` + `Sync` traits you can use `web::Data::new()` and - /// avoid double `Arc`. pub fn new(state: T) -> Data { Data(Arc::new(state)) }