You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: mod.rs
    path of file: ./repos/smartcore/src/neighbors
    
    the code of the file until where you have to start completion: //! # Nearest Neighbors
//!
//! The k-nearest neighbors (KNN) algorithm is a simple supervised machine learning algorithm that can be used to solve both classification and regression problems.
//! KNN is a non-parametric method that assumes that similar things exist in close proximity.
//!
//! During training the algorithms memorizes all training samples. To make a prediction it finds a predefined set of training samples closest in distance to 
    
    fn calc_weights(&self, distances: Vec<f64>) -> std::vec::Vec<f64> {
        match *self {
            KNNWeightFunction::Distance => {
                // if there are any points that has zero distance from one or more training points,
                // those training points are weighted as 1.0 and the other points as 0.0
                if distances.iter().any(|&e| e == 0f64) {
                    distances
                        .iter()
                        .map(|e| if *e == 0f64 { 1f64 } else { 0f64 })
                        .collect()
                } else {
                    distances.iter().map(|e| 1f64 / *e).collect()
                }
            }
            KNNWeightFunction::Uniform => vec![1f64; distances.len()],
        }
    }