mirror of
https://github.com/oSumAtrIX/free-librespot.git
synced 2025-12-19 18:04:20 +00:00
21 lines
437 B
Rust
21 lines
437 B
Rust
use std::collections::HashMap;
|
|
use std::ffi::{CString, CStr};
|
|
|
|
pub struct CStringCache {
|
|
cache: HashMap<String, CString>
|
|
}
|
|
|
|
impl CStringCache {
|
|
pub fn new() -> CStringCache {
|
|
CStringCache {
|
|
cache: HashMap::new()
|
|
}
|
|
}
|
|
|
|
pub fn intern(&mut self, string: &str) -> &CStr {
|
|
self.cache.entry(string.to_owned()).or_insert_with(|| {
|
|
CString::new(string).unwrap()
|
|
})
|
|
}
|
|
}
|
|
|