Skip to main content

oxilean_std/hashset/
oxihashset_traits.rs

1//! # OxiHashSet - Trait Implementations
2//!
3//! This module contains trait implementations for `OxiHashSet`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Default`
8//! - `Display`
9//! - `From`
10//! - `From`
11//! - `IntoIterator`
12//!
13//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
14
15use std::collections::HashSet as StdHashSet;
16use std::fmt;
17use std::hash::Hash;
18
19use super::functions::*;
20use super::oxihashset_type::OxiHashSet;
21
22impl<T: Eq + Hash + Clone> Default for OxiHashSet<T> {
23    fn default() -> Self {
24        Self::new()
25    }
26}
27
28impl<T: Eq + Hash + Clone + fmt::Display> fmt::Display for OxiHashSet<T> {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        let mut elems: Vec<String> = self.inner.iter().map(|e| e.to_string()).collect();
31        elems.sort();
32        write!(f, "{{{}}}", elems.join(", "))
33    }
34}
35
36impl<T: Eq + Hash + Clone> From<Vec<T>> for OxiHashSet<T> {
37    fn from(v: Vec<T>) -> Self {
38        Self {
39            inner: v.into_iter().collect(),
40        }
41    }
42}
43
44impl<T: Eq + Hash + Clone> From<StdHashSet<T>> for OxiHashSet<T> {
45    fn from(s: StdHashSet<T>) -> Self {
46        Self { inner: s }
47    }
48}
49
50impl<T: Eq + Hash + Clone> IntoIterator for OxiHashSet<T> {
51    type Item = T;
52    type IntoIter = std::collections::hash_set::IntoIter<T>;
53    fn into_iter(self) -> Self::IntoIter {
54        self.inner.into_iter()
55    }
56}