ahtml/arc_util.rs
1use std::sync::Arc;
2
3/// Make it possible to pass &x or x to a function, where x is
4/// `Arc<T>`, and have the function do the clone operation when
5/// needed.
6pub trait IntoArc<T> {
7 fn into_arc(self) -> Arc<T>;
8}
9
10impl<T> IntoArc<T> for T {
11 fn into_arc(self) -> Arc<T> {
12 Arc::new(self)
13 }
14}
15impl<T> IntoArc<T> for Arc<T> {
16 fn into_arc(self) -> Arc<T> {
17 self
18 }
19}
20impl<T> IntoArc<T> for &Arc<T> {
21 fn into_arc(self) -> Arc<T> {
22 Arc::clone(self)
23 }
24}