shacl_ast/ast/
message_map.rs
1use srdf::lang::Lang;
2use std::collections::HashMap;
3use std::str::FromStr;
4
5#[derive(Debug, Default, Clone)]
6pub struct MessageMap {
7 messages: HashMap<Option<Lang>, String>,
8}
9
10impl MessageMap {
11 pub fn new() -> Self {
12 Self::default()
13 }
14
15 pub fn with_message(mut self, lang: Option<Lang>, message: String) -> Self {
16 self.messages.insert(lang, message);
17 self
18 }
19
20 pub fn messages(&self) -> &HashMap<Option<Lang>, String> {
21 &self.messages
22 }
23
24 pub fn iter(&self) -> impl Iterator<Item = (&Option<Lang>, &String)> {
25 self.messages.iter()
26 }
27}
28
29impl FromStr for MessageMap {
30 type Err = ();
31
32 fn from_str(s: &str) -> Result<Self, Self::Err> {
33 Ok(Self {
34 messages: HashMap::from([(None, s.to_string())]),
35 })
36 }
37}