Skip to main content

rdf_model/
base_direction.rs

1// This is free and unencumbered software released into the public domain.
2
3/// A base direction for directional language-tagged strings.
4///
5/// See: <https://www.w3.org/TR/rdf12-concepts/#dfn-base-direction>
6#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
7#[cfg_attr(
8    feature = "borsh",
9    derive(borsh::BorshSerialize, borsh::BorshDeserialize)
10)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12pub enum BaseDirection {
13    /// The initial text direction is set to left-to-right (LTR)
14    #[default]
15    Ltr,
16
17    /// The initial text direction is set to right-to-left (RTL)
18    Rtl,
19}
20
21impl BaseDirection {
22    pub fn as_str(&self) -> &'static str {
23        match self {
24            Self::Ltr => "ltr",
25            Self::Rtl => "rtl",
26        }
27    }
28}
29
30#[cfg(feature = "oxrdf")]
31impl From<oxrdf::BaseDirection> for BaseDirection {
32    fn from(input: oxrdf::BaseDirection) -> Self {
33        use oxrdf::BaseDirection::*;
34        match input {
35            Ltr => Self::Ltr,
36            Rtl => Self::Rtl,
37        }
38    }
39}
40
41#[cfg(feature = "oxrdf")]
42impl From<BaseDirection> for oxrdf::BaseDirection {
43    fn from(input: BaseDirection) -> Self {
44        use BaseDirection::*;
45        match input {
46            Ltr => Self::Ltr,
47            Rtl => Self::Rtl,
48        }
49    }
50}