1
0
Fork 0
forked from wry/wry

seat: store pressed keys in a vector

This commit is contained in:
Julian Orth 2024-04-12 14:50:57 +02:00
parent 2cef936b12
commit 8d43eebc3d
4 changed files with 45 additions and 5 deletions

39
src/utils/vecset.rs Normal file
View file

@ -0,0 +1,39 @@
use std::ops::Deref;
pub struct VecSet<T> {
vec: Vec<T>,
}
impl<T> Default for VecSet<T> {
fn default() -> Self {
Self { vec: vec![] }
}
}
impl<T> Deref for VecSet<T> {
type Target = [T];
fn deref(&self) -> &Self::Target {
&self.vec
}
}
impl<T: PartialEq> VecSet<T> {
pub fn insert(&mut self, val: T) -> bool {
if self.vec.contains(&val) {
return false;
}
self.vec.push(val);
true
}
pub fn remove(&mut self, val: &T) -> bool {
for i in 0..self.vec.len() {
if self.vec[i] == *val {
self.vec.swap_remove(i);
return true;
}
}
false
}
}