kdtree 0.8.0

K-dimensional tree in Rust for fast geospatial indexing and nearest neighbors lookup
Documentation
use num_traits::Float;
use std::cmp::Ordering;

pub struct HeapElement<A, T> {
    pub distance: A,
    pub element: T,
}

impl<A: Float, T> Ord for HeapElement<A, T> {
    fn cmp(&self, other: &Self) -> Ordering {
        self.distance.partial_cmp(&other.distance).unwrap_or(Ordering::Equal)
    }
}

impl<A: Float, T> PartialOrd for HeapElement<A, T> {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl<A: Float, T> PartialOrd<A> for HeapElement<A, T>
where
    HeapElement<A, T>: PartialEq<A>,
{
    fn partial_cmp(&self, other: &A) -> Option<Ordering> {
        self.distance.partial_cmp(other)
    }
}

impl<A: Float, T> Eq for HeapElement<A, T> {}

impl<A: Float, T> PartialEq for HeapElement<A, T> {
    fn eq(&self, other: &Self) -> bool {
        self.distance == other.distance
    }
}

impl<A: Float, T> PartialEq<A> for HeapElement<A, T> {
    fn eq(&self, other: &A) -> bool {
        self.distance == *other
    }
}

impl<A: Float, T> From<HeapElement<A, T>> for (A, T) {
    fn from(e: HeapElement<A, T>) -> Self {
        (e.distance, e.element)
    }
}