Skip to main content

phoxal_model/simulation/
mod.rs

1//! Canonical simulation facts used after authored documents are loaded.
2
3pub mod capability;
4
5use std::collections::BTreeMap;
6
7use capability::Capability;
8
9#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)]
10#[serde(deny_unknown_fields)]
11pub struct Simulation {
12    capabilities: BTreeMap<String, Capability>,
13    links: BTreeMap<String, Link>,
14}
15
16#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
17#[serde(deny_unknown_fields)]
18pub struct Link {
19    contact_material: Option<String>,
20}
21
22impl Simulation {
23    #[doc(hidden)]
24    pub fn __new(
25        capabilities: BTreeMap<String, Capability>,
26        links: BTreeMap<String, Option<String>>,
27    ) -> Self {
28        Self {
29            capabilities,
30            links: links
31                .into_iter()
32                .map(|(id, contact_material)| (id, Link { contact_material }))
33                .collect(),
34        }
35    }
36
37    pub fn capabilities(&self) -> impl ExactSizeIterator<Item = (&str, &Capability)> {
38        self.capabilities
39            .iter()
40            .map(|(id, capability)| (id.as_str(), capability))
41    }
42
43    pub fn capability(&self, id: &str) -> Option<&Capability> {
44        self.capabilities.get(id)
45    }
46
47    pub fn links(&self) -> impl ExactSizeIterator<Item = (&str, &Link)> {
48        self.links.iter().map(|(id, link)| (id.as_str(), link))
49    }
50}
51
52impl Link {
53    #[must_use]
54    pub fn contact_material(&self) -> Option<&str> {
55        self.contact_material.as_deref()
56    }
57}