pub trait MetricSpace<UserImplementationType = ()> {
type UserData;
type Distance: Copy + PartialOrd + Bounded + Add<Output = Self::Distance>;
// Required method
fn distance(
&self,
other: &Self,
user_data: &Self::UserData,
) -> Self::Distance;
}
Expand description
Elements you’re searching for must be comparable using this trait.
You can ignore UserImplementationType
if you’re implementing MetricSpace
for your custom type.
However, if you’re implementing MetricSpace
for a type from std or another crate, then you need
to uniquely identify your implementation (that’s because of Rust’s Orphan Rules).
ⓘ
impl MetricSpace for MyInt {/*…*/}
/// That dummy struct disambiguates between yours and everyone else's impl for a tuple:
struct MyXYCoordinates;
impl MetricSpace<MyXYCoordinates> for (f32,f32) {/*…*/}
Required Associated Types§
Required Methods§
Sourcefn distance(&self, other: &Self, user_data: &Self::UserData) -> Self::Distance
fn distance(&self, other: &Self, user_data: &Self::UserData) -> Self::Distance
This function must return distance between two items that meets triangle inequality. Specifically, it MUST NOT return a squared distance (you must use sqrt if you use Euclidean distance)
user_data
—Whatever you want. Passed fromnew_with_user_data_*()
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.