sim_lib_standard_core/
registry.rs1use std::collections::BTreeMap;
4
5use sim_kernel::{Error, Result, Symbol};
6
7use crate::LanguageProfile;
8
9#[derive(Clone, Debug, Default)]
11pub struct ProfileRegistry {
12 profiles: BTreeMap<Symbol, LanguageProfile>,
13}
14
15impl ProfileRegistry {
16 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn register_profile(&mut self, profile: LanguageProfile) -> Result<()> {
24 let symbol = profile.symbol.clone();
25 if self.profiles.contains_key(&symbol) {
26 return Err(Error::DuplicateExport {
27 kind: "standard-profile",
28 symbol,
29 });
30 }
31 self.profiles.insert(symbol, profile);
32 Ok(())
33 }
34
35 pub fn profile(&self, symbol: &Symbol) -> Option<&LanguageProfile> {
37 self.profiles.get(symbol)
38 }
39
40 pub fn profiles(&self) -> impl Iterator<Item = &LanguageProfile> {
42 self.profiles.values()
43 }
44
45 pub fn len(&self) -> usize {
47 self.profiles.len()
48 }
49
50 pub fn is_empty(&self) -> bool {
52 self.profiles.is_empty()
53 }
54}