HashMap<PositionKey, Position>: Iterator

Why does this

pub struct Holdings {
    pub positions: HashMap<PositionKey, Position>,
}

impl Holdings {
    pub fn new() -> Self {
        Self {
            positions: HashMap::new(),
        }
    }

    pub fn getBySymbol2(&self, symbol: String) -> Vec<Position> {
        self.positions
            .filter(|(key, _)| key.symbol == symbol)
            .map(|(_, position)| position.clone())
            .collect()
    }

produce this error?

pub struct HashMap<K, V, S = RandomState> {

  • | ----------------------------------------- doesn't satisfy HashMap<PositionKey, Position>: Iterator*
  • |*
  • = note: the following trait bounds were not satisfied:*
  •        `HashMap<PositionKey, Position>: Iterator`*
    
  •        which is required by `&mut HashMap<PositionKey, Position>: Iterator`*
    

self.positions.iter().filter(...), not self.positions.filter(...)

1 Like