json_ld/core/
processing_mode.rs1use linked_data::{DeserializeLinkedData, SerializeLinkedData};
2use std::convert::TryFrom;
3use std::fmt;
4
5#[derive(
10 Default, Clone, Copy, PartialEq, Eq, Hash, Debug, SerializeLinkedData, DeserializeLinkedData,
11)]
12pub enum JsonLdProcessingMode {
13 #[ld(literal = "json-ld-1.0")]
15 JsonLd1_0,
16
17 #[default]
19 #[ld(literal = "json-ld-1.1")]
20 JsonLd1_1,
21}
22
23impl JsonLdProcessingMode {
24 #[inline(always)]
26 pub fn as_str(&self) -> &str {
27 match self {
28 JsonLdProcessingMode::JsonLd1_0 => "json-ld-1.0",
29 JsonLdProcessingMode::JsonLd1_1 => "json-ld-1.1",
30 }
31 }
32}
33
34impl<'a> TryFrom<&'a str> for JsonLdProcessingMode {
35 type Error = ();
36
37 fn try_from(name: &'a str) -> Result<JsonLdProcessingMode, ()> {
38 match name {
39 "json-ld-1.0" => Ok(JsonLdProcessingMode::JsonLd1_0),
40 "json-ld-1.1" => Ok(JsonLdProcessingMode::JsonLd1_1),
41 _ => Err(()),
42 }
43 }
44}
45
46impl fmt::Display for JsonLdProcessingMode {
47 #[inline(always)]
48 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49 write!(f, "{}", self.as_str())
50 }
51}