Provide impl<T> From<Arc<T>> for Data<T>

This commit is contained in:
Sven Allers 2020-05-14 11:49:23 +02:00
parent 92ce975d87
commit 3ee1fbfa91
1 changed files with 13 additions and 0 deletions

View File

@ -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)
}
} }