diff --git a/lib/src/io/format.rs b/lib/src/io/format.rs index 4e2ceea9..24bfbfce 100644 --- a/lib/src/io/format.rs +++ b/lib/src/io/format.rs @@ -38,6 +38,7 @@ impl GraphFormat { /// /// assert_eq!(GraphFormat::NTriples.iri(), "http://www.w3.org/ns/formats/N-Triples") /// ``` + #[inline] pub fn iri(self) -> &'static str { match self { GraphFormat::NTriples => "http://www.w3.org/ns/formats/N-Triples", @@ -53,6 +54,7 @@ impl GraphFormat { /// /// assert_eq!(GraphFormat::NTriples.media_type(), "application/n-triples") /// ``` + #[inline] pub fn media_type(self) -> &'static str { match self { GraphFormat::NTriples => "application/n-triples", @@ -68,6 +70,7 @@ impl GraphFormat { /// /// assert_eq!(GraphFormat::NTriples.file_extension(), "nt") /// ``` + #[inline] pub fn file_extension(self) -> &'static str { match self { GraphFormat::NTriples => "nt", @@ -141,6 +144,7 @@ impl DatasetFormat { /// /// assert_eq!(DatasetFormat::NQuads.iri(), "http://www.w3.org/ns/formats/N-Quads") /// ``` + #[inline] pub fn iri(self) -> &'static str { match self { DatasetFormat::NQuads => "http://www.w3.org/ns/formats/N-Quads", @@ -155,6 +159,7 @@ impl DatasetFormat { /// /// assert_eq!(DatasetFormat::NQuads.media_type(), "application/n-quads") /// ``` + #[inline] pub fn media_type(self) -> &'static str { match self { DatasetFormat::NQuads => "application/n-quads", @@ -169,6 +174,7 @@ impl DatasetFormat { /// /// assert_eq!(DatasetFormat::NQuads.file_extension(), "nq") /// ``` + #[inline] pub fn file_extension(self) -> &'static str { match self { DatasetFormat::NQuads => "nq", diff --git a/lib/src/model/blank_node.rs b/lib/src/model/blank_node.rs index 9d4cd7ed..acff84ea 100644 --- a/lib/src/model/blank_node.rs +++ b/lib/src/model/blank_node.rs @@ -71,6 +71,7 @@ impl BlankNode { } /// Returns the underlying ID of this blank node + #[inline] pub fn as_str(&self) -> &str { match &self.0 { BlankNodeContent::Named(id) => id, @@ -79,6 +80,7 @@ impl BlankNode { } /// Returns the underlying ID of this blank node + #[inline] pub fn into_string(self) -> String { match self.0 { BlankNodeContent::Named(id) => id, @@ -86,6 +88,7 @@ impl BlankNode { } } + #[inline] pub fn as_ref(&self) -> BlankNodeRef<'_> { BlankNodeRef(match &self.0 { BlankNodeContent::Named(id) => BlankNodeRefContent::Named(id.as_str()), @@ -98,6 +101,7 @@ impl BlankNode { } impl fmt::Display for BlankNode { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.as_ref().fmt(f) } @@ -105,6 +109,7 @@ impl fmt::Display for BlankNode { impl Default for BlankNode { /// Builds a new RDF [blank node](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node) with a unique id + #[inline] fn default() -> Self { Self::new_from_unique_id(random::()) } @@ -166,6 +171,7 @@ impl<'a> BlankNodeRef<'a> { } /// Returns the underlying ID of this blank node + #[inline] pub fn as_str(self) -> &'a str { match self.0 { BlankNodeRefContent::Named(id) => id, @@ -174,6 +180,7 @@ impl<'a> BlankNodeRef<'a> { } /// Returns the internal numerical ID of this blank node, if it exists + #[inline] pub(crate) fn id(&self) -> Option { match self.0 { BlankNodeRefContent::Named(_) => None, @@ -181,6 +188,7 @@ impl<'a> BlankNodeRef<'a> { } } + #[inline] pub fn into_owned(self) -> BlankNode { BlankNode(match self.0 { BlankNodeRefContent::Named(id) => BlankNodeContent::Named(id.to_owned()), @@ -193,36 +201,42 @@ impl<'a> BlankNodeRef<'a> { } impl fmt::Display for BlankNodeRef<'_> { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { rio::BlankNode::from(*self).fmt(f) } } impl<'a> From<&'a BlankNode> for BlankNodeRef<'a> { + #[inline] fn from(node: &'a BlankNode) -> Self { node.as_ref() } } impl<'a> From> for BlankNode { + #[inline] fn from(node: BlankNodeRef<'a>) -> Self { node.into_owned() } } impl<'a> From> for rio::BlankNode<'a> { + #[inline] fn from(node: BlankNodeRef<'a>) -> Self { rio::BlankNode { id: node.as_str() } } } impl PartialEq for BlankNodeRef<'_> { + #[inline] fn eq(&self, other: &BlankNode) -> bool { *self == other.as_ref() } } impl PartialEq> for BlankNode { + #[inline] fn eq(&self, other: &BlankNodeRef<'_>) -> bool { self.as_ref() == *other } @@ -328,6 +342,7 @@ fn to_integer_id(id: &str) -> Option { pub struct BlankNodeIdParseError {} impl fmt::Display for BlankNodeIdParseError { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "The blank node identifier is invalid") } diff --git a/lib/src/model/literal.rs b/lib/src/model/literal.rs index ab5bcdb3..2c9154f4 100644 --- a/lib/src/model/literal.rs +++ b/lib/src/model/literal.rs @@ -45,11 +45,13 @@ enum LiteralContent { impl Literal { /// Builds an RDF [simple literal](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal) + #[inline] pub fn new_simple_literal(value: impl Into) -> Self { Literal(LiteralContent::String(value.into())) } /// Builds an RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal) with a [datatype](https://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri) + #[inline] pub fn new_typed_literal(value: impl Into, datatype: impl Into) -> Self { let value = value.into(); let datatype = datatype.into(); @@ -61,6 +63,7 @@ impl Literal { } /// Builds an RDF [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) + #[inline] pub fn new_language_tagged_literal( value: impl Into, language: impl Into, @@ -81,6 +84,7 @@ impl Literal { /// /// Except if you really know what you do, /// you should use [`new_language_tagged_literal`](#method.new_language_tagged_literal). + #[inline] pub fn new_language_tagged_literal_unchecked( value: impl Into, language: impl Into, @@ -92,6 +96,7 @@ impl Literal { } /// The literal [lexical form](https://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form) + #[inline] pub fn value(&self) -> &str { self.as_ref().value() } @@ -100,6 +105,7 @@ impl Literal { /// /// Language tags are defined by the [BCP47](https://tools.ietf.org/html/bcp47). /// They are normalized to lowercase by this implementation. + #[inline] pub fn language(&self) -> Option<&str> { self.as_ref().language() } @@ -108,6 +114,7 @@ impl Literal { /// /// The datatype of [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) is always [rdf:langString](http://www.w3.org/1999/02/22-rdf-syntax-ns#langString). /// The datatype of [simple literals](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal) is [xsd:string](http://www.w3.org/2001/XMLSchema#string). + #[inline] pub fn datatype(&self) -> NamedNodeRef<'_> { self.as_ref().datatype() } @@ -116,10 +123,12 @@ impl Literal { /// /// 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](http://www.w3.org/2001/XMLSchema#string). + #[inline] pub fn is_plain(&self) -> bool { self.as_ref().is_plain() } + #[inline] pub fn as_ref(&self) -> LiteralRef<'_> { LiteralRef(match &self.0 { LiteralContent::String(value) => LiteralRefContent::String(value), @@ -134,6 +143,7 @@ impl Literal { } /// Extract components from this literal + #[inline] pub fn destruct(self) -> (String, Option, Option) { match self.0 { LiteralContent::String(s) => (s, None, None), @@ -146,30 +156,35 @@ impl Literal { } impl fmt::Display for Literal { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.as_ref().fmt(f) } } impl<'a> From<&'a str> for Literal { + #[inline] fn from(value: &'a str) -> Self { Literal(LiteralContent::String(value.into())) } } impl From for Literal { + #[inline] fn from(value: String) -> Self { Literal(LiteralContent::String(value)) } } impl<'a> From> for Literal { + #[inline] fn from(value: Cow<'a, str>) -> Self { Literal(LiteralContent::String(value.into())) } } impl From for Literal { + #[inline] fn from(value: bool) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -179,6 +194,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: i128) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -188,6 +204,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: i64) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -197,6 +214,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: i32) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -206,6 +224,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: i16) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -215,6 +234,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: u64) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -224,6 +244,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: u32) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -233,6 +254,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: u16) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -242,6 +264,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: f32) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -251,6 +274,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: f64) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -260,6 +284,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: Decimal) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -269,6 +294,7 @@ impl From for Literal { } impl From for Literal { + #[inline] fn from(value: DateTime) -> Self { Literal(LiteralContent::TypedLiteral { value: value.to_string(), @@ -278,6 +304,7 @@ impl From for Literal { } impl From