mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 18:44:35 +01:00
Provide impl<T> From<Arc<T>> for Data<T> (#1509)
This commit is contained in:
parent
4fc99d4a6f
commit
201090d7a2
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Add option to create `Data<T>` from `Arc<T>` [#1509]
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
* Resources and Scopes can now access non-overridden data types set on App (or containing scopes) when setting their own data. [#1486]
|
* Resources and Scopes can now access non-overridden data types set on App (or containing scopes) when setting their own data. [#1486]
|
||||||
@ -11,7 +15,7 @@
|
|||||||
* Bump minimum supported Rust version to 1.40
|
* Bump minimum supported Rust version to 1.40
|
||||||
|
|
||||||
[#1485]: https://github.com/actix/actix-web/pull/1485
|
[#1485]: https://github.com/actix/actix-web/pull/1485
|
||||||
|
[#1509]: https://github.com/actix/actix-web/pull/1509
|
||||||
|
|
||||||
## [3.0.0-alpha.2] - 2020-05-08
|
## [3.0.0-alpha.2] - 2020-05-08
|
||||||
|
|
||||||
|
13
src/data.rs
13
src/data.rs
@ -103,6 +103,12 @@ impl<T> Clone for Data<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> From<Arc<T>> for Data<T> {
|
||||||
|
fn from(arc: Arc<T>) -> Self {
|
||||||
|
Data(arc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: 'static> FromRequest for Data<T> {
|
impl<T: 'static> FromRequest for Data<T> {
|
||||||
type Config = ();
|
type Config = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
@ -281,4 +287,11 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(num.load(Ordering::SeqCst), 0);
|
assert_eq!(num.load(Ordering::SeqCst), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_data_from_arc() {
|
||||||
|
let data_new = Data::new(String::from("test-123"));
|
||||||
|
let data_from_arc = Data::from(Arc::new(String::from("test-123")));
|
||||||
|
assert_eq!(data_new.0, data_from_arc.0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user