1use std::rc::Rc;
2use std::sync::Arc;
3
4pub trait Metric<T> {
5 type Error: std::error::Error;
6
7 fn distance(&self, value: &T) -> Result<f64, Self::Error>;
13}
14
15impl<T, M: Metric<T> + ?Sized> Metric<T> for &'_ M {
16 type Error = M::Error;
17
18 fn distance(&self, value: &T) -> Result<f64, Self::Error> {
19 (**self).distance(value)
20 }
21}
22
23impl<T, M: Metric<T> + ?Sized> Metric<T> for Box<M> {
25 type Error = M::Error;
26
27 fn distance(&self, value: &T) -> Result<f64, Self::Error> {
28 (**self).distance(value)
29 }
30}
31
32impl<T, M: Metric<T> + ?Sized> Metric<T> for Rc<M> {
33 type Error = M::Error;
34
35 fn distance(&self, value: &T) -> Result<f64, Self::Error> {
36 (**self).distance(value)
37 }
38}
39
40impl<T, M: Metric<T> + ?Sized> Metric<T> for Arc<M> {
41 type Error = M::Error;
42
43 fn distance(&self, value: &T) -> Result<f64, Self::Error> {
44 (**self).distance(value)
45 }
46}