excel_writer/
shared_strings.rs1use std::{borrow::Cow, collections::HashMap};
2
3use serde::Serialize;
4
5#[derive(Debug, Copy, Clone, Serialize, Eq, PartialEq, Hash)]
6pub(crate) struct SharedStringIndex(pub(crate) usize);
7
8pub(crate) type SharedString = Cow<'static, str>;
9
10#[derive(Default, Serialize)]
11pub(crate) struct SharedStrings {
12 pub(crate) strings: HashMap<SharedString, SharedStringIndex>,
13}
14
15impl SharedStrings {
16 pub(crate) fn insert(&mut self, value: Cow<'static, str>) -> SharedStringIndex {
17 let len = self.strings.len();
18
19 *self
20 .strings
21 .entry(value)
22 .or_insert_with(|| SharedStringIndex(len))
23 }
24}