rust-lib/src/vector/distinct.rs
Martin Berg Alstad 0898a50166 Added MultipartFile extractors.
Moved cfg macro to lib where possible.

Changed some features, and made some deps optional
2024-06-30 20:17:44 +02:00

27 lines
507 B
Rust

pub trait Distinct {
fn distinct(&mut self);
}
impl<T: PartialEq + Clone> Distinct for Vec<T> {
fn distinct(&mut self) {
*self = self.iter().fold(vec![], |mut acc, x| {
if !acc.contains(x) {
acc.push(x.clone());
}
acc
});
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_distinct() {
let mut vec = vec![1, 2, 3, 1, 2, 3];
vec.distinct();
assert_eq!(vec, vec![1, 2, 3]);
}
}