mirror of https://github.com/fafhrd91/actix-web
Provide impl<T> From<Arc<T>> for Data<T>
This commit is contained in:
parent
92ce975d87
commit
3ee1fbfa91
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