skrifa/outline/glyf/hint/
storage.rs

1//! Storage area.
2
3use super::{cow_slice::CowSlice, error::HintErrorKind};
4
5/// Backing store for the storage area.
6///
7/// This is just a wrapper for [`CowSlice`] that converts out of bounds
8/// accesses to appropriate errors.
9pub struct Storage<'a>(CowSlice<'a>);
10
11impl Storage<'_> {
12    pub fn get(&self, index: usize) -> Result<i32, HintErrorKind> {
13        self.0
14            .get(index)
15            .ok_or(HintErrorKind::InvalidStorageIndex(index))
16    }
17
18    pub fn set(&mut self, index: usize, value: i32) -> Result<(), HintErrorKind> {
19        self.0
20            .set(index, value)
21            .ok_or(HintErrorKind::InvalidStorageIndex(index))
22    }
23}
24
25impl<'a> From<CowSlice<'a>> for Storage<'a> {
26    fn from(value: CowSlice<'a>) -> Self {
27        Self(value)
28    }
29}