use crate::PsdLayer;
use std::collections::HashMap;
use std::ops::{Deref, Range};
#[derive(Debug)]
pub(crate) struct Layers {
items: Vec<PsdLayer>,
item_indices: HashMap<String, usize>,
}
impl Layers {
pub fn new() -> Self {
Layers {
items: vec![],
item_indices: HashMap::new(),
}
}
pub fn with_capacity(capacity: usize) -> Self {
Layers {
items: Vec::with_capacity(capacity),
item_indices: HashMap::with_capacity(capacity),
}
}
#[allow(missing_docs)]
pub fn item_by_name(&self, name: &str) -> Option<&PsdLayer> {
match self.item_indices.get(name) {
Some(item_idx) => self.items.get(*item_idx),
None => None,
}
}
#[allow(missing_docs)]
pub(in crate) fn push(&mut self, name: String, item: PsdLayer) {
self.items.push(item);
self.item_indices.insert(name, self.items.len() - 1);
}
}
impl Deref for Layers {
type Target = Vec<PsdLayer>;
fn deref(&self) -> &Self::Target {
&self.items
}
}