OxRDF: makes more function const

pull/680/head
Tpt 1 year ago committed by Thomas Tanon
parent 99c3a4cce4
commit d1cb4cecbd
  1. 4
      lib/oxrdf/src/blank_node.rs
  2. 14
      lib/oxrdf/src/literal.rs
  3. 4
      lib/oxrdf/src/variable.rs

@ -180,7 +180,7 @@ impl<'a> BlankNodeRef<'a> {
/// Returns the underlying ID of this blank node. /// Returns the underlying ID of this blank node.
#[inline] #[inline]
pub fn as_str(self) -> &'a str { pub const fn as_str(self) -> &'a str {
match self.0 { match self.0 {
BlankNodeRefContent::Named(id) => id, BlankNodeRefContent::Named(id) => id,
BlankNodeRefContent::Anonymous { str, .. } => str, BlankNodeRefContent::Anonymous { str, .. } => str,
@ -197,7 +197,7 @@ impl<'a> BlankNodeRef<'a> {
/// # Result::<_,oxrdf::BlankNodeIdParseError>::Ok(()) /// # Result::<_,oxrdf::BlankNodeIdParseError>::Ok(())
/// ``` /// ```
#[inline] #[inline]
pub fn unique_id(&self) -> Option<u128> { pub const fn unique_id(&self) -> Option<u128> {
match self.0 { match self.0 {
BlankNodeRefContent::Named(_) => None, BlankNodeRefContent::Named(_) => None,
BlankNodeRefContent::Anonymous { id, .. } => Some(id), BlankNodeRefContent::Anonymous { id, .. } => Some(id),

@ -459,7 +459,7 @@ enum LiteralRefContent<'a> {
impl<'a> LiteralRef<'a> { impl<'a> LiteralRef<'a> {
/// Builds an RDF [simple literal](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal). /// Builds an RDF [simple literal](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal).
#[inline] #[inline]
pub fn new_simple_literal(value: &'a str) -> Self { pub const fn new_simple_literal(value: &'a str) -> Self {
LiteralRef(LiteralRefContent::String(value)) LiteralRef(LiteralRefContent::String(value))
} }
@ -482,13 +482,13 @@ impl<'a> LiteralRef<'a> {
/// ///
/// [`Literal::new_language_tagged_literal()`] is a safe version of this constructor and should be used for untrusted data. /// [`Literal::new_language_tagged_literal()`] is a safe version of this constructor and should be used for untrusted data.
#[inline] #[inline]
pub fn new_language_tagged_literal_unchecked(value: &'a str, language: &'a str) -> Self { pub const fn new_language_tagged_literal_unchecked(value: &'a str, language: &'a str) -> Self {
LiteralRef(LiteralRefContent::LanguageTaggedString { value, language }) LiteralRef(LiteralRefContent::LanguageTaggedString { value, language })
} }
/// The literal [lexical form](https://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form) /// The literal [lexical form](https://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form)
#[inline] #[inline]
pub fn value(self) -> &'a str { pub const fn value(self) -> &'a str {
match self.0 { match self.0 {
LiteralRefContent::String(value) LiteralRefContent::String(value)
| LiteralRefContent::LanguageTaggedString { value, .. } | LiteralRefContent::LanguageTaggedString { value, .. }
@ -501,7 +501,7 @@ impl<'a> LiteralRef<'a> {
/// Language tags are defined by the [BCP47](https://tools.ietf.org/html/bcp47). /// Language tags are defined by the [BCP47](https://tools.ietf.org/html/bcp47).
/// They are normalized to lowercase by this implementation. /// They are normalized to lowercase by this implementation.
#[inline] #[inline]
pub fn language(self) -> Option<&'a str> { pub const fn language(self) -> Option<&'a str> {
match self.0 { match self.0 {
LiteralRefContent::LanguageTaggedString { language, .. } => Some(language), LiteralRefContent::LanguageTaggedString { language, .. } => Some(language),
_ => None, _ => None,
@ -513,7 +513,7 @@ impl<'a> LiteralRef<'a> {
/// The datatype of [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) is always [rdf:langString](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string). /// The datatype of [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) is always [rdf:langString](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string).
/// The datatype of [simple literals](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal) is [xsd:string](https://www.w3.org/TR/xmlschema11-2/#string). /// The datatype of [simple literals](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal) is [xsd:string](https://www.w3.org/TR/xmlschema11-2/#string).
#[inline] #[inline]
pub fn datatype(self) -> NamedNodeRef<'a> { pub const fn datatype(self) -> NamedNodeRef<'a> {
match self.0 { match self.0 {
LiteralRefContent::String(_) => xsd::STRING, LiteralRefContent::String(_) => xsd::STRING,
LiteralRefContent::LanguageTaggedString { .. } => rdf::LANG_STRING, LiteralRefContent::LanguageTaggedString { .. } => rdf::LANG_STRING,
@ -526,7 +526,7 @@ impl<'a> LiteralRef<'a> {
/// It returns true if the literal is a [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) /// It returns true if the literal is a [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string)
/// or has the datatype [xsd:string](https://www.w3.org/TR/xmlschema11-2/#string). /// or has the datatype [xsd:string](https://www.w3.org/TR/xmlschema11-2/#string).
#[inline] #[inline]
pub fn is_plain(self) -> bool { pub const fn is_plain(self) -> bool {
matches!( matches!(
self.0, self.0,
LiteralRefContent::String(_) | LiteralRefContent::LanguageTaggedString { .. } LiteralRefContent::String(_) | LiteralRefContent::LanguageTaggedString { .. }
@ -552,7 +552,7 @@ impl<'a> LiteralRef<'a> {
/// Extract components from this literal /// Extract components from this literal
#[inline] #[inline]
pub fn destruct(self) -> (&'a str, Option<NamedNodeRef<'a>>, Option<&'a str>) { pub const fn destruct(self) -> (&'a str, Option<NamedNodeRef<'a>>, Option<&'a str>) {
match self.0 { match self.0 {
LiteralRefContent::String(s) => (s, None, None), LiteralRefContent::String(s) => (s, None, None),
LiteralRefContent::LanguageTaggedString { value, language } => { LiteralRefContent::LanguageTaggedString { value, language } => {

@ -96,12 +96,12 @@ impl<'a> VariableRef<'a> {
/// ///
/// [`Variable::new()`] is a safe version of this constructor and should be used for untrusted data. /// [`Variable::new()`] is a safe version of this constructor and should be used for untrusted data.
#[inline] #[inline]
pub fn new_unchecked(name: &'a str) -> Self { pub const fn new_unchecked(name: &'a str) -> Self {
Self { name } Self { name }
} }
#[inline] #[inline]
pub fn as_str(&self) -> &str { pub const fn as_str(self) -> &'a str {
self.name self.name
} }

Loading…
Cancel
Save