mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +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]
|
||||
|
||||
### Added
|
||||
|
||||
* Add option to create `Data<T>` from `Arc<T>` [#1509]
|
||||
|
||||
### Changed
|
||||
|
||||
* 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
|
||||
|
||||
[#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
|
||||
|
||||
|
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> {
|
||||
type Config = ();
|
||||
type Error = Error;
|
||||
@ -281,4 +287,11 @@ mod tests {
|
||||
|
||||
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