Adds #[inline] annotations to simple public functions

pull/46/head
Tpt 5 years ago
parent 10e4c1518d
commit fdc0dbbeef
  1. 6
      lib/src/io/format.rs
  2. 15
      lib/src/model/blank_node.rs
  3. 52
      lib/src/model/literal.rs
  4. 23
      lib/src/model/named_node.rs
  5. 100
      lib/src/model/triple.rs
  6. 23
      lib/src/sparql/model.rs
  7. 2
      python/src/memory_store.rs

@ -38,6 +38,7 @@ impl GraphFormat {
/// ///
/// assert_eq!(GraphFormat::NTriples.iri(), "http://www.w3.org/ns/formats/N-Triples") /// assert_eq!(GraphFormat::NTriples.iri(), "http://www.w3.org/ns/formats/N-Triples")
/// ``` /// ```
#[inline]
pub fn iri(self) -> &'static str { pub fn iri(self) -> &'static str {
match self { match self {
GraphFormat::NTriples => "http://www.w3.org/ns/formats/N-Triples", 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") /// assert_eq!(GraphFormat::NTriples.media_type(), "application/n-triples")
/// ``` /// ```
#[inline]
pub fn media_type(self) -> &'static str { pub fn media_type(self) -> &'static str {
match self { match self {
GraphFormat::NTriples => "application/n-triples", GraphFormat::NTriples => "application/n-triples",
@ -68,6 +70,7 @@ impl GraphFormat {
/// ///
/// assert_eq!(GraphFormat::NTriples.file_extension(), "nt") /// assert_eq!(GraphFormat::NTriples.file_extension(), "nt")
/// ``` /// ```
#[inline]
pub fn file_extension(self) -> &'static str { pub fn file_extension(self) -> &'static str {
match self { match self {
GraphFormat::NTriples => "nt", GraphFormat::NTriples => "nt",
@ -141,6 +144,7 @@ impl DatasetFormat {
/// ///
/// assert_eq!(DatasetFormat::NQuads.iri(), "http://www.w3.org/ns/formats/N-Quads") /// assert_eq!(DatasetFormat::NQuads.iri(), "http://www.w3.org/ns/formats/N-Quads")
/// ``` /// ```
#[inline]
pub fn iri(self) -> &'static str { pub fn iri(self) -> &'static str {
match self { match self {
DatasetFormat::NQuads => "http://www.w3.org/ns/formats/N-Quads", 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") /// assert_eq!(DatasetFormat::NQuads.media_type(), "application/n-quads")
/// ``` /// ```
#[inline]
pub fn media_type(self) -> &'static str { pub fn media_type(self) -> &'static str {
match self { match self {
DatasetFormat::NQuads => "application/n-quads", DatasetFormat::NQuads => "application/n-quads",
@ -169,6 +174,7 @@ impl DatasetFormat {
/// ///
/// assert_eq!(DatasetFormat::NQuads.file_extension(), "nq") /// assert_eq!(DatasetFormat::NQuads.file_extension(), "nq")
/// ``` /// ```
#[inline]
pub fn file_extension(self) -> &'static str { pub fn file_extension(self) -> &'static str {
match self { match self {
DatasetFormat::NQuads => "nq", DatasetFormat::NQuads => "nq",

@ -71,6 +71,7 @@ impl BlankNode {
} }
/// Returns the underlying ID of this blank node /// Returns the underlying ID of this blank node
#[inline]
pub fn as_str(&self) -> &str { pub fn as_str(&self) -> &str {
match &self.0 { match &self.0 {
BlankNodeContent::Named(id) => id, BlankNodeContent::Named(id) => id,
@ -79,6 +80,7 @@ impl BlankNode {
} }
/// Returns the underlying ID of this blank node /// Returns the underlying ID of this blank node
#[inline]
pub fn into_string(self) -> String { pub fn into_string(self) -> String {
match self.0 { match self.0 {
BlankNodeContent::Named(id) => id, BlankNodeContent::Named(id) => id,
@ -86,6 +88,7 @@ impl BlankNode {
} }
} }
#[inline]
pub fn as_ref(&self) -> BlankNodeRef<'_> { pub fn as_ref(&self) -> BlankNodeRef<'_> {
BlankNodeRef(match &self.0 { BlankNodeRef(match &self.0 {
BlankNodeContent::Named(id) => BlankNodeRefContent::Named(id.as_str()), BlankNodeContent::Named(id) => BlankNodeRefContent::Named(id.as_str()),
@ -98,6 +101,7 @@ impl BlankNode {
} }
impl fmt::Display for BlankNode { impl fmt::Display for BlankNode {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.as_ref().fmt(f) self.as_ref().fmt(f)
} }
@ -105,6 +109,7 @@ impl fmt::Display for BlankNode {
impl Default 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 /// Builds a new RDF [blank node](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node) with a unique id
#[inline]
fn default() -> Self { fn default() -> Self {
Self::new_from_unique_id(random::<u128>()) Self::new_from_unique_id(random::<u128>())
} }
@ -166,6 +171,7 @@ impl<'a> BlankNodeRef<'a> {
} }
/// Returns the underlying ID of this blank node /// Returns the underlying ID of this blank node
#[inline]
pub fn as_str(self) -> &'a str { pub fn as_str(self) -> &'a str {
match self.0 { match self.0 {
BlankNodeRefContent::Named(id) => id, BlankNodeRefContent::Named(id) => id,
@ -174,6 +180,7 @@ impl<'a> BlankNodeRef<'a> {
} }
/// Returns the internal numerical ID of this blank node, if it exists /// Returns the internal numerical ID of this blank node, if it exists
#[inline]
pub(crate) fn id(&self) -> Option<u128> { pub(crate) fn id(&self) -> Option<u128> {
match self.0 { match self.0 {
BlankNodeRefContent::Named(_) => None, BlankNodeRefContent::Named(_) => None,
@ -181,6 +188,7 @@ impl<'a> BlankNodeRef<'a> {
} }
} }
#[inline]
pub fn into_owned(self) -> BlankNode { pub fn into_owned(self) -> BlankNode {
BlankNode(match self.0 { BlankNode(match self.0 {
BlankNodeRefContent::Named(id) => BlankNodeContent::Named(id.to_owned()), BlankNodeRefContent::Named(id) => BlankNodeContent::Named(id.to_owned()),
@ -193,36 +201,42 @@ impl<'a> BlankNodeRef<'a> {
} }
impl fmt::Display for BlankNodeRef<'_> { impl fmt::Display for BlankNodeRef<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
rio::BlankNode::from(*self).fmt(f) rio::BlankNode::from(*self).fmt(f)
} }
} }
impl<'a> From<&'a BlankNode> for BlankNodeRef<'a> { impl<'a> From<&'a BlankNode> for BlankNodeRef<'a> {
#[inline]
fn from(node: &'a BlankNode) -> Self { fn from(node: &'a BlankNode) -> Self {
node.as_ref() node.as_ref()
} }
} }
impl<'a> From<BlankNodeRef<'a>> for BlankNode { impl<'a> From<BlankNodeRef<'a>> for BlankNode {
#[inline]
fn from(node: BlankNodeRef<'a>) -> Self { fn from(node: BlankNodeRef<'a>) -> Self {
node.into_owned() node.into_owned()
} }
} }
impl<'a> From<BlankNodeRef<'a>> for rio::BlankNode<'a> { impl<'a> From<BlankNodeRef<'a>> for rio::BlankNode<'a> {
#[inline]
fn from(node: BlankNodeRef<'a>) -> Self { fn from(node: BlankNodeRef<'a>) -> Self {
rio::BlankNode { id: node.as_str() } rio::BlankNode { id: node.as_str() }
} }
} }
impl PartialEq<BlankNode> for BlankNodeRef<'_> { impl PartialEq<BlankNode> for BlankNodeRef<'_> {
#[inline]
fn eq(&self, other: &BlankNode) -> bool { fn eq(&self, other: &BlankNode) -> bool {
*self == other.as_ref() *self == other.as_ref()
} }
} }
impl PartialEq<BlankNodeRef<'_>> for BlankNode { impl PartialEq<BlankNodeRef<'_>> for BlankNode {
#[inline]
fn eq(&self, other: &BlankNodeRef<'_>) -> bool { fn eq(&self, other: &BlankNodeRef<'_>) -> bool {
self.as_ref() == *other self.as_ref() == *other
} }
@ -328,6 +342,7 @@ fn to_integer_id(id: &str) -> Option<u128> {
pub struct BlankNodeIdParseError {} pub struct BlankNodeIdParseError {}
impl fmt::Display for BlankNodeIdParseError { impl fmt::Display for BlankNodeIdParseError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "The blank node identifier is invalid") write!(f, "The blank node identifier is invalid")
} }

@ -45,11 +45,13 @@ enum LiteralContent {
impl Literal { impl Literal {
/// 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]
pub fn new_simple_literal(value: impl Into<String>) -> Self { pub fn new_simple_literal(value: impl Into<String>) -> Self {
Literal(LiteralContent::String(value.into())) 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) /// 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<String>, datatype: impl Into<NamedNode>) -> Self { pub fn new_typed_literal(value: impl Into<String>, datatype: impl Into<NamedNode>) -> Self {
let value = value.into(); let value = value.into();
let datatype = datatype.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) /// Builds an RDF [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string)
#[inline]
pub fn new_language_tagged_literal( pub fn new_language_tagged_literal(
value: impl Into<String>, value: impl Into<String>,
language: impl Into<String>, language: impl Into<String>,
@ -81,6 +84,7 @@ impl Literal {
/// ///
/// Except if you really know what you do, /// Except if you really know what you do,
/// you should use [`new_language_tagged_literal`](#method.new_language_tagged_literal). /// you should use [`new_language_tagged_literal`](#method.new_language_tagged_literal).
#[inline]
pub fn new_language_tagged_literal_unchecked( pub fn new_language_tagged_literal_unchecked(
value: impl Into<String>, value: impl Into<String>,
language: impl Into<String>, language: impl Into<String>,
@ -92,6 +96,7 @@ impl Literal {
} }
/// 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]
pub fn value(&self) -> &str { pub fn value(&self) -> &str {
self.as_ref().value() self.as_ref().value()
} }
@ -100,6 +105,7 @@ impl Literal {
/// ///
/// 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]
pub fn language(&self) -> Option<&str> { pub fn language(&self) -> Option<&str> {
self.as_ref().language() 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 [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). /// 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<'_> { pub fn datatype(&self) -> NamedNodeRef<'_> {
self.as_ref().datatype() 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) /// 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). /// or has the datatype [xsd:string](http://www.w3.org/2001/XMLSchema#string).
#[inline]
pub fn is_plain(&self) -> bool { pub fn is_plain(&self) -> bool {
self.as_ref().is_plain() self.as_ref().is_plain()
} }
#[inline]
pub fn as_ref(&self) -> LiteralRef<'_> { pub fn as_ref(&self) -> LiteralRef<'_> {
LiteralRef(match &self.0 { LiteralRef(match &self.0 {
LiteralContent::String(value) => LiteralRefContent::String(value), LiteralContent::String(value) => LiteralRefContent::String(value),
@ -134,6 +143,7 @@ impl Literal {
} }
/// Extract components from this literal /// Extract components from this literal
#[inline]
pub fn destruct(self) -> (String, Option<NamedNode>, Option<String>) { pub fn destruct(self) -> (String, Option<NamedNode>, Option<String>) {
match self.0 { match self.0 {
LiteralContent::String(s) => (s, None, None), LiteralContent::String(s) => (s, None, None),
@ -146,30 +156,35 @@ impl Literal {
} }
impl fmt::Display for Literal { impl fmt::Display for Literal {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.as_ref().fmt(f) self.as_ref().fmt(f)
} }
} }
impl<'a> From<&'a str> for Literal { impl<'a> From<&'a str> for Literal {
#[inline]
fn from(value: &'a str) -> Self { fn from(value: &'a str) -> Self {
Literal(LiteralContent::String(value.into())) Literal(LiteralContent::String(value.into()))
} }
} }
impl From<String> for Literal { impl From<String> for Literal {
#[inline]
fn from(value: String) -> Self { fn from(value: String) -> Self {
Literal(LiteralContent::String(value)) Literal(LiteralContent::String(value))
} }
} }
impl<'a> From<Cow<'a, str>> for Literal { impl<'a> From<Cow<'a, str>> for Literal {
#[inline]
fn from(value: Cow<'a, str>) -> Self { fn from(value: Cow<'a, str>) -> Self {
Literal(LiteralContent::String(value.into())) Literal(LiteralContent::String(value.into()))
} }
} }
impl From<bool> for Literal { impl From<bool> for Literal {
#[inline]
fn from(value: bool) -> Self { fn from(value: bool) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -179,6 +194,7 @@ impl From<bool> for Literal {
} }
impl From<i128> for Literal { impl From<i128> for Literal {
#[inline]
fn from(value: i128) -> Self { fn from(value: i128) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -188,6 +204,7 @@ impl From<i128> for Literal {
} }
impl From<i64> for Literal { impl From<i64> for Literal {
#[inline]
fn from(value: i64) -> Self { fn from(value: i64) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -197,6 +214,7 @@ impl From<i64> for Literal {
} }
impl From<i32> for Literal { impl From<i32> for Literal {
#[inline]
fn from(value: i32) -> Self { fn from(value: i32) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -206,6 +224,7 @@ impl From<i32> for Literal {
} }
impl From<i16> for Literal { impl From<i16> for Literal {
#[inline]
fn from(value: i16) -> Self { fn from(value: i16) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -215,6 +234,7 @@ impl From<i16> for Literal {
} }
impl From<u64> for Literal { impl From<u64> for Literal {
#[inline]
fn from(value: u64) -> Self { fn from(value: u64) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -224,6 +244,7 @@ impl From<u64> for Literal {
} }
impl From<u32> for Literal { impl From<u32> for Literal {
#[inline]
fn from(value: u32) -> Self { fn from(value: u32) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -233,6 +254,7 @@ impl From<u32> for Literal {
} }
impl From<u16> for Literal { impl From<u16> for Literal {
#[inline]
fn from(value: u16) -> Self { fn from(value: u16) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -242,6 +264,7 @@ impl From<u16> for Literal {
} }
impl From<f32> for Literal { impl From<f32> for Literal {
#[inline]
fn from(value: f32) -> Self { fn from(value: f32) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -251,6 +274,7 @@ impl From<f32> for Literal {
} }
impl From<f64> for Literal { impl From<f64> for Literal {
#[inline]
fn from(value: f64) -> Self { fn from(value: f64) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -260,6 +284,7 @@ impl From<f64> for Literal {
} }
impl From<Decimal> for Literal { impl From<Decimal> for Literal {
#[inline]
fn from(value: Decimal) -> Self { fn from(value: Decimal) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -269,6 +294,7 @@ impl From<Decimal> for Literal {
} }
impl From<DateTime> for Literal { impl From<DateTime> for Literal {
#[inline]
fn from(value: DateTime) -> Self { fn from(value: DateTime) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -278,6 +304,7 @@ impl From<DateTime> for Literal {
} }
impl From<Time> for Literal { impl From<Time> for Literal {
#[inline]
fn from(value: Time) -> Self { fn from(value: Time) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -287,6 +314,7 @@ impl From<Time> for Literal {
} }
impl From<Date> for Literal { impl From<Date> for Literal {
#[inline]
fn from(value: Date) -> Self { fn from(value: Date) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -296,6 +324,7 @@ impl From<Date> for Literal {
} }
impl From<GYearMonth> for Literal { impl From<GYearMonth> for Literal {
#[inline]
fn from(value: GYearMonth) -> Self { fn from(value: GYearMonth) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -305,6 +334,7 @@ impl From<GYearMonth> for Literal {
} }
impl From<GYear> for Literal { impl From<GYear> for Literal {
#[inline]
fn from(value: GYear) -> Self { fn from(value: GYear) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -314,6 +344,7 @@ impl From<GYear> for Literal {
} }
impl From<GMonthDay> for Literal { impl From<GMonthDay> for Literal {
#[inline]
fn from(value: GMonthDay) -> Self { fn from(value: GMonthDay) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -323,6 +354,7 @@ impl From<GMonthDay> for Literal {
} }
impl From<GMonth> for Literal { impl From<GMonth> for Literal {
#[inline]
fn from(value: GMonth) -> Self { fn from(value: GMonth) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -332,6 +364,7 @@ impl From<GMonth> for Literal {
} }
impl From<GDay> for Literal { impl From<GDay> for Literal {
#[inline]
fn from(value: GDay) -> Self { fn from(value: GDay) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -341,6 +374,7 @@ impl From<GDay> for Literal {
} }
impl From<Duration> for Literal { impl From<Duration> for Literal {
#[inline]
fn from(value: Duration) -> Self { fn from(value: Duration) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -350,6 +384,7 @@ impl From<Duration> for Literal {
} }
impl From<YearMonthDuration> for Literal { impl From<YearMonthDuration> for Literal {
#[inline]
fn from(value: YearMonthDuration) -> Self { fn from(value: YearMonthDuration) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -359,6 +394,7 @@ impl From<YearMonthDuration> for Literal {
} }
impl From<DayTimeDuration> for Literal { impl From<DayTimeDuration> for Literal {
#[inline]
fn from(value: DayTimeDuration) -> Self { fn from(value: DayTimeDuration) -> Self {
Literal(LiteralContent::TypedLiteral { Literal(LiteralContent::TypedLiteral {
value: value.to_string(), value: value.to_string(),
@ -404,11 +440,13 @@ 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]
pub fn new_simple_literal(value: &'a str) -> Self { pub fn new_simple_literal(value: &'a str) -> Self {
LiteralRef(LiteralRefContent::String(value)) LiteralRef(LiteralRefContent::String(value))
} }
/// 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) /// 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: &'a str, datatype: impl Into<NamedNodeRef<'a>>) -> Self { pub fn new_typed_literal(value: &'a str, datatype: impl Into<NamedNodeRef<'a>>) -> Self {
let datatype = datatype.into(); let datatype = datatype.into();
LiteralRef(if datatype == xsd::STRING { LiteralRef(if datatype == xsd::STRING {
@ -426,11 +464,13 @@ impl<'a> LiteralRef<'a> {
/// ///
/// Except if you really know what you do, /// Except if you really know what you do,
/// you should use [`new_language_tagged_literal`](#method.new_language_tagged_literal). /// you should use [`new_language_tagged_literal`](#method.new_language_tagged_literal).
#[inline]
pub fn new_language_tagged_literal_unchecked(value: &'a str, language: &'a str) -> Self { pub 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]
pub fn value(self) -> &'a str { pub fn value(self) -> &'a str {
match self.0 { match self.0 {
LiteralRefContent::String(value) LiteralRefContent::String(value)
@ -443,6 +483,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]
pub fn language(self) -> Option<&'a str> { pub fn language(self) -> Option<&'a str> {
match self.0 { match self.0 {
LiteralRefContent::LanguageTaggedString { language, .. } => Some(language), LiteralRefContent::LanguageTaggedString { language, .. } => Some(language),
@ -454,6 +495,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](http://www.w3.org/1999/02/22-rdf-syntax-ns#langString). /// 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). /// 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<'a> { pub fn datatype(self) -> NamedNodeRef<'a> {
match self.0 { match self.0 {
LiteralRefContent::String(_) => xsd::STRING, LiteralRefContent::String(_) => xsd::STRING,
@ -466,6 +508,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](http://www.w3.org/2001/XMLSchema#string). /// or has the datatype [xsd:string](http://www.w3.org/2001/XMLSchema#string).
#[inline]
pub fn is_plain(self) -> bool { pub fn is_plain(self) -> bool {
match self.0 { match self.0 {
LiteralRefContent::String(_) | LiteralRefContent::LanguageTaggedString { .. } => true, LiteralRefContent::String(_) | LiteralRefContent::LanguageTaggedString { .. } => true,
@ -473,6 +516,7 @@ impl<'a> LiteralRef<'a> {
} }
} }
#[inline]
pub fn into_owned(self) -> Literal { pub fn into_owned(self) -> Literal {
Literal(match self.0 { Literal(match self.0 {
LiteralRefContent::String(value) => LiteralContent::String(value.to_owned()), LiteralRefContent::String(value) => LiteralContent::String(value.to_owned()),
@ -490,6 +534,7 @@ impl<'a> LiteralRef<'a> {
} }
/// Extract components from this literal /// Extract components from this literal
#[inline]
pub fn destruct(self) -> (&'a str, Option<NamedNodeRef<'a>>, Option<&'a str>) { pub 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),
@ -502,24 +547,28 @@ impl<'a> LiteralRef<'a> {
} }
impl fmt::Display for LiteralRef<'_> { impl fmt::Display for LiteralRef<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
rio::Literal::from(*self).fmt(f) rio::Literal::from(*self).fmt(f)
} }
} }
impl<'a> From<&'a Literal> for LiteralRef<'a> { impl<'a> From<&'a Literal> for LiteralRef<'a> {
#[inline]
fn from(node: &'a Literal) -> Self { fn from(node: &'a Literal) -> Self {
node.as_ref() node.as_ref()
} }
} }
impl<'a> From<LiteralRef<'a>> for Literal { impl<'a> From<LiteralRef<'a>> for Literal {
#[inline]
fn from(node: LiteralRef<'a>) -> Self { fn from(node: LiteralRef<'a>) -> Self {
node.into_owned() node.into_owned()
} }
} }
impl<'a> From<LiteralRef<'a>> for rio::Literal<'a> { impl<'a> From<LiteralRef<'a>> for rio::Literal<'a> {
#[inline]
fn from(literal: LiteralRef<'a>) -> Self { fn from(literal: LiteralRef<'a>) -> Self {
match literal.0 { match literal.0 {
LiteralRefContent::String(value) => rio::Literal::Simple { value }, LiteralRefContent::String(value) => rio::Literal::Simple { value },
@ -535,18 +584,21 @@ impl<'a> From<LiteralRef<'a>> for rio::Literal<'a> {
} }
impl<'a> From<&'a str> for LiteralRef<'a> { impl<'a> From<&'a str> for LiteralRef<'a> {
#[inline]
fn from(value: &'a str) -> Self { fn from(value: &'a str) -> Self {
LiteralRef(LiteralRefContent::String(value)) LiteralRef(LiteralRefContent::String(value))
} }
} }
impl PartialEq<Literal> for LiteralRef<'_> { impl PartialEq<Literal> for LiteralRef<'_> {
#[inline]
fn eq(&self, other: &Literal) -> bool { fn eq(&self, other: &Literal) -> bool {
*self == other.as_ref() *self == other.as_ref()
} }
} }
impl PartialEq<LiteralRef<'_>> for Literal { impl PartialEq<LiteralRef<'_>> for Literal {
#[inline]
fn eq(&self, other: &LiteralRef<'_>) -> bool { fn eq(&self, other: &LiteralRef<'_>) -> bool {
self.as_ref() == *other self.as_ref() == *other
} }

@ -30,6 +30,7 @@ impl NamedNode {
Self::new(iri) Self::new(iri)
} }
#[inline]
pub(crate) fn new_from_iri(iri: Iri<String>) -> Self { pub(crate) fn new_from_iri(iri: Iri<String>) -> Self {
Self::new_unchecked(iri.into_inner()) Self::new_unchecked(iri.into_inner())
} }
@ -39,48 +40,57 @@ impl NamedNode {
/// It is the caller's responsibility to ensure that `iri` is a valid IRI. /// It is the caller's responsibility to ensure that `iri` is a valid IRI.
/// ///
/// Except if you really know what you do, you should use [`parse`](#method.parse). /// Except if you really know what you do, you should use [`parse`](#method.parse).
#[inline]
pub fn new_unchecked(iri: impl Into<String>) -> Self { pub fn new_unchecked(iri: impl Into<String>) -> Self {
Self { iri: iri.into() } Self { iri: iri.into() }
} }
#[inline]
pub fn as_str(&self) -> &str { pub fn as_str(&self) -> &str {
self.iri.as_str() self.iri.as_str()
} }
#[inline]
pub fn into_string(self) -> String { pub fn into_string(self) -> String {
self.iri self.iri
} }
#[inline]
pub fn as_ref(&self) -> NamedNodeRef<'_> { pub fn as_ref(&self) -> NamedNodeRef<'_> {
NamedNodeRef::new_unchecked(&self.iri) NamedNodeRef::new_unchecked(&self.iri)
} }
} }
impl fmt::Display for NamedNode { impl fmt::Display for NamedNode {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.as_ref().fmt(f) self.as_ref().fmt(f)
} }
} }
impl PartialEq<str> for NamedNode { impl PartialEq<str> for NamedNode {
#[inline]
fn eq(&self, other: &str) -> bool { fn eq(&self, other: &str) -> bool {
self.as_str() == other self.as_str() == other
} }
} }
impl PartialEq<NamedNode> for str { impl PartialEq<NamedNode> for str {
#[inline]
fn eq(&self, other: &NamedNode) -> bool { fn eq(&self, other: &NamedNode) -> bool {
self == other.as_str() self == other.as_str()
} }
} }
impl PartialEq<&str> for NamedNode { impl PartialEq<&str> for NamedNode {
#[inline]
fn eq(&self, other: &&str) -> bool { fn eq(&self, other: &&str) -> bool {
self == *other self == *other
} }
} }
impl PartialEq<NamedNode> for &str { impl PartialEq<NamedNode> for &str {
#[inline]
fn eq(&self, other: &NamedNode) -> bool { fn eq(&self, other: &NamedNode) -> bool {
*self == other *self == other
} }
@ -109,6 +119,7 @@ impl<'a> NamedNodeRef<'a> {
Ok(Self::new_from_iri(Iri::parse(iri)?)) Ok(Self::new_from_iri(Iri::parse(iri)?))
} }
#[inline]
pub(crate) fn new_from_iri(iri: Iri<&'a str>) -> Self { pub(crate) fn new_from_iri(iri: Iri<&'a str>) -> Self {
Self::new_unchecked(iri.into_inner()) Self::new_unchecked(iri.into_inner())
} }
@ -118,26 +129,31 @@ impl<'a> NamedNodeRef<'a> {
/// It is the caller's responsibility to ensure that `iri` is a valid IRI. /// It is the caller's responsibility to ensure that `iri` is a valid IRI.
/// ///
/// Except if you really know what you do, you should use [`parse`](#method.parse). /// Except if you really know what you do, you should use [`parse`](#method.parse).
#[inline]
pub const fn new_unchecked(iri: &'a str) -> Self { pub const fn new_unchecked(iri: &'a str) -> Self {
Self { iri } Self { iri }
} }
#[inline]
pub const fn as_str(self) -> &'a str { pub const fn as_str(self) -> &'a str {
self.iri self.iri
} }
#[inline]
pub fn into_owned(self) -> NamedNode { pub fn into_owned(self) -> NamedNode {
NamedNode::new_unchecked(self.iri) NamedNode::new_unchecked(self.iri)
} }
} }
impl fmt::Display for NamedNodeRef<'_> { impl fmt::Display for NamedNodeRef<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
rio::NamedNode::from(*self).fmt(f) rio::NamedNode::from(*self).fmt(f)
} }
} }
impl From<NamedNodeRef<'_>> for NamedNode { impl From<NamedNodeRef<'_>> for NamedNode {
#[inline]
fn from(node: NamedNodeRef<'_>) -> Self { fn from(node: NamedNodeRef<'_>) -> Self {
node.into_owned() node.into_owned()
} }
@ -150,42 +166,49 @@ impl<'a> From<&'a NamedNode> for NamedNodeRef<'a> {
} }
impl<'a> From<NamedNodeRef<'a>> for rio::NamedNode<'a> { impl<'a> From<NamedNodeRef<'a>> for rio::NamedNode<'a> {
#[inline]
fn from(node: NamedNodeRef<'a>) -> Self { fn from(node: NamedNodeRef<'a>) -> Self {
rio::NamedNode { iri: node.as_str() } rio::NamedNode { iri: node.as_str() }
} }
} }
impl PartialEq<NamedNode> for NamedNodeRef<'_> { impl PartialEq<NamedNode> for NamedNodeRef<'_> {
#[inline]
fn eq(&self, other: &NamedNode) -> bool { fn eq(&self, other: &NamedNode) -> bool {
self.as_str() == other.as_str() self.as_str() == other.as_str()
} }
} }
impl PartialEq<NamedNodeRef<'_>> for NamedNode { impl PartialEq<NamedNodeRef<'_>> for NamedNode {
#[inline]
fn eq(&self, other: &NamedNodeRef<'_>) -> bool { fn eq(&self, other: &NamedNodeRef<'_>) -> bool {
self.as_str() == other.as_str() self.as_str() == other.as_str()
} }
} }
impl PartialEq<str> for NamedNodeRef<'_> { impl PartialEq<str> for NamedNodeRef<'_> {
#[inline]
fn eq(&self, other: &str) -> bool { fn eq(&self, other: &str) -> bool {
self.as_str() == other self.as_str() == other
} }
} }
impl PartialEq<NamedNodeRef<'_>> for str { impl PartialEq<NamedNodeRef<'_>> for str {
#[inline]
fn eq(&self, other: &NamedNodeRef<'_>) -> bool { fn eq(&self, other: &NamedNodeRef<'_>) -> bool {
self == other.as_str() self == other.as_str()
} }
} }
impl PartialEq<&str> for NamedNodeRef<'_> { impl PartialEq<&str> for NamedNodeRef<'_> {
#[inline]
fn eq(&self, other: &&str) -> bool { fn eq(&self, other: &&str) -> bool {
self == *other self == *other
} }
} }
impl PartialEq<NamedNodeRef<'_>> for &str { impl PartialEq<NamedNodeRef<'_>> for &str {
#[inline]
fn eq(&self, other: &NamedNodeRef<'_>) -> bool { fn eq(&self, other: &NamedNodeRef<'_>) -> bool {
*self == other *self == other
} }

@ -13,14 +13,17 @@ pub enum NamedOrBlankNode {
} }
impl NamedOrBlankNode { impl NamedOrBlankNode {
#[inline]
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
self.as_ref().is_named_node() self.as_ref().is_named_node()
} }
#[inline]
pub fn is_blank_node(&self) -> bool { pub fn is_blank_node(&self) -> bool {
self.as_ref().is_blank_node() self.as_ref().is_blank_node()
} }
#[inline]
pub fn as_ref(&self) -> NamedOrBlankNodeRef<'_> { pub fn as_ref(&self) -> NamedOrBlankNodeRef<'_> {
match self { match self {
Self::NamedNode(node) => NamedOrBlankNodeRef::NamedNode(node.as_ref()), Self::NamedNode(node) => NamedOrBlankNodeRef::NamedNode(node.as_ref()),
@ -30,30 +33,35 @@ impl NamedOrBlankNode {
} }
impl fmt::Display for NamedOrBlankNode { impl fmt::Display for NamedOrBlankNode {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.as_ref().fmt(f) self.as_ref().fmt(f)
} }
} }
impl From<NamedNode> for NamedOrBlankNode { impl From<NamedNode> for NamedOrBlankNode {
#[inline]
fn from(node: NamedNode) -> Self { fn from(node: NamedNode) -> Self {
Self::NamedNode(node) Self::NamedNode(node)
} }
} }
impl From<NamedNodeRef<'_>> for NamedOrBlankNode { impl From<NamedNodeRef<'_>> for NamedOrBlankNode {
#[inline]
fn from(node: NamedNodeRef<'_>) -> Self { fn from(node: NamedNodeRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
} }
impl From<BlankNode> for NamedOrBlankNode { impl From<BlankNode> for NamedOrBlankNode {
#[inline]
fn from(node: BlankNode) -> Self { fn from(node: BlankNode) -> Self {
Self::BlankNode(node) Self::BlankNode(node)
} }
} }
impl From<BlankNodeRef<'_>> for NamedOrBlankNode { impl From<BlankNodeRef<'_>> for NamedOrBlankNode {
#[inline]
fn from(node: BlankNodeRef<'_>) -> Self { fn from(node: BlankNodeRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
@ -67,6 +75,7 @@ pub enum NamedOrBlankNodeRef<'a> {
} }
impl<'a> NamedOrBlankNodeRef<'a> { impl<'a> NamedOrBlankNodeRef<'a> {
#[inline]
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
match self { match self {
Self::NamedNode(_) => true, Self::NamedNode(_) => true,
@ -74,6 +83,7 @@ impl<'a> NamedOrBlankNodeRef<'a> {
} }
} }
#[inline]
pub fn is_blank_node(&self) -> bool { pub fn is_blank_node(&self) -> bool {
match self { match self {
Self::NamedNode(_) => false, Self::NamedNode(_) => false,
@ -81,6 +91,7 @@ impl<'a> NamedOrBlankNodeRef<'a> {
} }
} }
#[inline]
pub fn into_owned(self) -> NamedOrBlankNode { pub fn into_owned(self) -> NamedOrBlankNode {
match self { match self {
Self::NamedNode(node) => NamedOrBlankNode::NamedNode(node.into_owned()), Self::NamedNode(node) => NamedOrBlankNode::NamedNode(node.into_owned()),
@ -90,6 +101,7 @@ impl<'a> NamedOrBlankNodeRef<'a> {
} }
impl fmt::Display for NamedOrBlankNodeRef<'_> { impl fmt::Display for NamedOrBlankNodeRef<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::NamedNode(node) => node.fmt(f), Self::NamedNode(node) => node.fmt(f),
@ -99,42 +111,49 @@ impl fmt::Display for NamedOrBlankNodeRef<'_> {
} }
impl<'a> From<NamedNodeRef<'a>> for NamedOrBlankNodeRef<'a> { impl<'a> From<NamedNodeRef<'a>> for NamedOrBlankNodeRef<'a> {
#[inline]
fn from(node: NamedNodeRef<'a>) -> Self { fn from(node: NamedNodeRef<'a>) -> Self {
Self::NamedNode(node) Self::NamedNode(node)
} }
} }
impl<'a> From<&'a NamedNode> for NamedOrBlankNodeRef<'a> { impl<'a> From<&'a NamedNode> for NamedOrBlankNodeRef<'a> {
#[inline]
fn from(node: &'a NamedNode) -> Self { fn from(node: &'a NamedNode) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
impl<'a> From<BlankNodeRef<'a>> for NamedOrBlankNodeRef<'a> { impl<'a> From<BlankNodeRef<'a>> for NamedOrBlankNodeRef<'a> {
#[inline]
fn from(node: BlankNodeRef<'a>) -> Self { fn from(node: BlankNodeRef<'a>) -> Self {
Self::BlankNode(node) Self::BlankNode(node)
} }
} }
impl<'a> From<&'a BlankNode> for NamedOrBlankNodeRef<'a> { impl<'a> From<&'a BlankNode> for NamedOrBlankNodeRef<'a> {
#[inline]
fn from(node: &'a BlankNode) -> Self { fn from(node: &'a BlankNode) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
impl<'a> From<&'a NamedOrBlankNode> for NamedOrBlankNodeRef<'a> { impl<'a> From<&'a NamedOrBlankNode> for NamedOrBlankNodeRef<'a> {
#[inline]
fn from(node: &'a NamedOrBlankNode) -> Self { fn from(node: &'a NamedOrBlankNode) -> Self {
node.as_ref() node.as_ref()
} }
} }
impl<'a> From<NamedOrBlankNodeRef<'a>> for NamedOrBlankNode { impl<'a> From<NamedOrBlankNodeRef<'a>> for NamedOrBlankNode {
#[inline]
fn from(node: NamedOrBlankNodeRef<'a>) -> Self { fn from(node: NamedOrBlankNodeRef<'a>) -> Self {
node.into_owned() node.into_owned()
} }
} }
impl<'a> From<NamedOrBlankNodeRef<'a>> for rio::NamedOrBlankNode<'a> { impl<'a> From<NamedOrBlankNodeRef<'a>> for rio::NamedOrBlankNode<'a> {
#[inline]
fn from(node: NamedOrBlankNodeRef<'a>) -> Self { fn from(node: NamedOrBlankNodeRef<'a>) -> Self {
match node { match node {
NamedOrBlankNodeRef::NamedNode(node) => rio::NamedNode::from(node).into(), NamedOrBlankNodeRef::NamedNode(node) => rio::NamedNode::from(node).into(),
@ -153,18 +172,22 @@ pub enum Term {
} }
impl Term { impl Term {
#[inline]
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
self.as_ref().is_named_node() self.as_ref().is_named_node()
} }
#[inline]
pub fn is_blank_node(&self) -> bool { pub fn is_blank_node(&self) -> bool {
self.as_ref().is_blank_node() self.as_ref().is_blank_node()
} }
#[inline]
pub fn is_literal(&self) -> bool { pub fn is_literal(&self) -> bool {
self.as_ref().is_literal() self.as_ref().is_literal()
} }
#[inline]
pub fn as_ref(&self) -> TermRef<'_> { pub fn as_ref(&self) -> TermRef<'_> {
match self { match self {
Self::NamedNode(node) => TermRef::NamedNode(node.as_ref()), Self::NamedNode(node) => TermRef::NamedNode(node.as_ref()),
@ -175,48 +198,56 @@ impl Term {
} }
impl fmt::Display for Term { impl fmt::Display for Term {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.as_ref().fmt(f) self.as_ref().fmt(f)
} }
} }
impl From<NamedNode> for Term { impl From<NamedNode> for Term {
#[inline]
fn from(node: NamedNode) -> Self { fn from(node: NamedNode) -> Self {
Self::NamedNode(node) Self::NamedNode(node)
} }
} }
impl From<NamedNodeRef<'_>> for Term { impl From<NamedNodeRef<'_>> for Term {
#[inline]
fn from(node: NamedNodeRef<'_>) -> Self { fn from(node: NamedNodeRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
} }
impl From<BlankNode> for Term { impl From<BlankNode> for Term {
#[inline]
fn from(node: BlankNode) -> Self { fn from(node: BlankNode) -> Self {
Self::BlankNode(node) Self::BlankNode(node)
} }
} }
impl From<BlankNodeRef<'_>> for Term { impl From<BlankNodeRef<'_>> for Term {
#[inline]
fn from(node: BlankNodeRef<'_>) -> Self { fn from(node: BlankNodeRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
} }
impl From<Literal> for Term { impl From<Literal> for Term {
#[inline]
fn from(literal: Literal) -> Self { fn from(literal: Literal) -> Self {
Self::Literal(literal) Self::Literal(literal)
} }
} }
impl From<LiteralRef<'_>> for Term { impl From<LiteralRef<'_>> for Term {
#[inline]
fn from(literal: LiteralRef<'_>) -> Self { fn from(literal: LiteralRef<'_>) -> Self {
literal.into_owned().into() literal.into_owned().into()
} }
} }
impl From<NamedOrBlankNode> for Term { impl From<NamedOrBlankNode> for Term {
#[inline]
fn from(node: NamedOrBlankNode) -> Self { fn from(node: NamedOrBlankNode) -> Self {
match node { match node {
NamedOrBlankNode::NamedNode(node) => node.into(), NamedOrBlankNode::NamedNode(node) => node.into(),
@ -226,6 +257,7 @@ impl From<NamedOrBlankNode> for Term {
} }
impl From<NamedOrBlankNodeRef<'_>> for Term { impl From<NamedOrBlankNodeRef<'_>> for Term {
#[inline]
fn from(node: NamedOrBlankNodeRef<'_>) -> Self { fn from(node: NamedOrBlankNodeRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
@ -241,6 +273,7 @@ pub enum TermRef<'a> {
} }
impl<'a> TermRef<'a> { impl<'a> TermRef<'a> {
#[inline]
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
match self { match self {
Self::NamedNode(_) => true, Self::NamedNode(_) => true,
@ -248,6 +281,7 @@ impl<'a> TermRef<'a> {
} }
} }
#[inline]
pub fn is_blank_node(&self) -> bool { pub fn is_blank_node(&self) -> bool {
match self { match self {
Self::BlankNode(_) => true, Self::BlankNode(_) => true,
@ -255,6 +289,7 @@ impl<'a> TermRef<'a> {
} }
} }
#[inline]
pub fn is_literal(&self) -> bool { pub fn is_literal(&self) -> bool {
match self { match self {
Self::Literal(_) => true, Self::Literal(_) => true,
@ -262,6 +297,7 @@ impl<'a> TermRef<'a> {
} }
} }
#[inline]
pub fn into_owned(self) -> Term { pub fn into_owned(self) -> Term {
match self { match self {
Self::NamedNode(node) => Term::NamedNode(node.into_owned()), Self::NamedNode(node) => Term::NamedNode(node.into_owned()),
@ -272,6 +308,7 @@ impl<'a> TermRef<'a> {
} }
impl fmt::Display for TermRef<'_> { impl fmt::Display for TermRef<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::NamedNode(node) => node.fmt(f), Self::NamedNode(node) => node.fmt(f),
@ -282,42 +319,49 @@ impl fmt::Display for TermRef<'_> {
} }
impl<'a> From<NamedNodeRef<'a>> for TermRef<'a> { impl<'a> From<NamedNodeRef<'a>> for TermRef<'a> {
#[inline]
fn from(node: NamedNodeRef<'a>) -> Self { fn from(node: NamedNodeRef<'a>) -> Self {
Self::NamedNode(node) Self::NamedNode(node)
} }
} }
impl<'a> From<&'a NamedNode> for TermRef<'a> { impl<'a> From<&'a NamedNode> for TermRef<'a> {
#[inline]
fn from(node: &'a NamedNode) -> Self { fn from(node: &'a NamedNode) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
impl<'a> From<BlankNodeRef<'a>> for TermRef<'a> { impl<'a> From<BlankNodeRef<'a>> for TermRef<'a> {
#[inline]
fn from(node: BlankNodeRef<'a>) -> Self { fn from(node: BlankNodeRef<'a>) -> Self {
Self::BlankNode(node) Self::BlankNode(node)
} }
} }
impl<'a> From<&'a BlankNode> for TermRef<'a> { impl<'a> From<&'a BlankNode> for TermRef<'a> {
#[inline]
fn from(node: &'a BlankNode) -> Self { fn from(node: &'a BlankNode) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
impl<'a> From<LiteralRef<'a>> for TermRef<'a> { impl<'a> From<LiteralRef<'a>> for TermRef<'a> {
#[inline]
fn from(literal: LiteralRef<'a>) -> Self { fn from(literal: LiteralRef<'a>) -> Self {
Self::Literal(literal) Self::Literal(literal)
} }
} }
impl<'a> From<&'a Literal> for TermRef<'a> { impl<'a> From<&'a Literal> for TermRef<'a> {
#[inline]
fn from(literal: &'a Literal) -> Self { fn from(literal: &'a Literal) -> Self {
literal.as_ref().into() literal.as_ref().into()
} }
} }
impl<'a> From<NamedOrBlankNodeRef<'a>> for TermRef<'a> { impl<'a> From<NamedOrBlankNodeRef<'a>> for TermRef<'a> {
#[inline]
fn from(node: NamedOrBlankNodeRef<'a>) -> Self { fn from(node: NamedOrBlankNodeRef<'a>) -> Self {
match node { match node {
NamedOrBlankNodeRef::NamedNode(node) => node.into(), NamedOrBlankNodeRef::NamedNode(node) => node.into(),
@ -327,24 +371,28 @@ impl<'a> From<NamedOrBlankNodeRef<'a>> for TermRef<'a> {
} }
impl<'a> From<&'a NamedOrBlankNode> for TermRef<'a> { impl<'a> From<&'a NamedOrBlankNode> for TermRef<'a> {
#[inline]
fn from(node: &'a NamedOrBlankNode) -> Self { fn from(node: &'a NamedOrBlankNode) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
impl<'a> From<&'a Term> for TermRef<'a> { impl<'a> From<&'a Term> for TermRef<'a> {
#[inline]
fn from(node: &'a Term) -> Self { fn from(node: &'a Term) -> Self {
node.as_ref() node.as_ref()
} }
} }
impl<'a> From<TermRef<'a>> for Term { impl<'a> From<TermRef<'a>> for Term {
#[inline]
fn from(node: TermRef<'a>) -> Self { fn from(node: TermRef<'a>) -> Self {
node.into_owned() node.into_owned()
} }
} }
impl<'a> From<TermRef<'a>> for rio::Term<'a> { impl<'a> From<TermRef<'a>> for rio::Term<'a> {
#[inline]
fn from(node: TermRef<'a>) -> Self { fn from(node: TermRef<'a>) -> Self {
match node { match node {
TermRef::NamedNode(node) => rio::NamedNode::from(node).into(), TermRef::NamedNode(node) => rio::NamedNode::from(node).into(),
@ -369,6 +417,7 @@ pub struct Triple {
impl Triple { impl Triple {
/// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple)
#[inline]
pub fn new( pub fn new(
subject: impl Into<NamedOrBlankNode>, subject: impl Into<NamedOrBlankNode>,
predicate: impl Into<NamedNode>, predicate: impl Into<NamedNode>,
@ -412,6 +461,7 @@ impl Triple {
} }
/// Encodes that this triple is in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) /// Encodes that this triple is in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset)
#[inline]
pub fn in_graph(self, graph_name: impl Into<GraphName>) -> Quad { pub fn in_graph(self, graph_name: impl Into<GraphName>) -> Quad {
Quad { Quad {
subject: self.subject, subject: self.subject,
@ -421,6 +471,7 @@ impl Triple {
} }
} }
#[inline]
pub fn as_ref(&self) -> TripleRef<'_> { pub fn as_ref(&self) -> TripleRef<'_> {
TripleRef { TripleRef {
subject: self.subject.as_ref(), subject: self.subject.as_ref(),
@ -431,6 +482,7 @@ impl Triple {
} }
impl fmt::Display for Triple { impl fmt::Display for Triple {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.as_ref().fmt(f) self.as_ref().fmt(f)
} }
@ -451,6 +503,7 @@ pub struct TripleRef<'a> {
impl<'a> TripleRef<'a> { impl<'a> TripleRef<'a> {
/// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple)
#[inline]
pub fn new( pub fn new(
subject: impl Into<NamedOrBlankNodeRef<'a>>, subject: impl Into<NamedOrBlankNodeRef<'a>>,
predicate: impl Into<NamedNodeRef<'a>>, predicate: impl Into<NamedNodeRef<'a>>,
@ -464,6 +517,7 @@ impl<'a> TripleRef<'a> {
} }
/// Encodes that this triple is in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) /// Encodes that this triple is in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset)
#[inline]
pub fn in_graph(self, graph_name: impl Into<GraphNameRef<'a>>) -> QuadRef<'a> { pub fn in_graph(self, graph_name: impl Into<GraphNameRef<'a>>) -> QuadRef<'a> {
QuadRef { QuadRef {
subject: self.subject, subject: self.subject,
@ -473,6 +527,7 @@ impl<'a> TripleRef<'a> {
} }
} }
#[inline]
pub fn into_owned(self) -> Triple { pub fn into_owned(self) -> Triple {
Triple { Triple {
subject: self.subject.into_owned(), subject: self.subject.into_owned(),
@ -483,24 +538,28 @@ impl<'a> TripleRef<'a> {
} }
impl fmt::Display for TripleRef<'_> { impl fmt::Display for TripleRef<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
rio::Triple::from(*self).fmt(f) rio::Triple::from(*self).fmt(f)
} }
} }
impl<'a> From<&'a Triple> for TripleRef<'a> { impl<'a> From<&'a Triple> for TripleRef<'a> {
#[inline]
fn from(triple: &'a Triple) -> Self { fn from(triple: &'a Triple) -> Self {
triple.as_ref() triple.as_ref()
} }
} }
impl<'a> From<TripleRef<'a>> for Triple { impl<'a> From<TripleRef<'a>> for Triple {
#[inline]
fn from(triple: TripleRef<'a>) -> Self { fn from(triple: TripleRef<'a>) -> Self {
triple.into_owned() triple.into_owned()
} }
} }
impl<'a> From<TripleRef<'a>> for rio::Triple<'a> { impl<'a> From<TripleRef<'a>> for rio::Triple<'a> {
#[inline]
fn from(triple: TripleRef<'a>) -> Self { fn from(triple: TripleRef<'a>) -> Self {
rio::Triple { rio::Triple {
subject: triple.subject.into(), subject: triple.subject.into(),
@ -520,18 +579,22 @@ pub enum GraphName {
} }
impl GraphName { impl GraphName {
#[inline]
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
self.as_ref().is_named_node() self.as_ref().is_named_node()
} }
#[inline]
pub fn is_blank_node(&self) -> bool { pub fn is_blank_node(&self) -> bool {
self.as_ref().is_blank_node() self.as_ref().is_blank_node()
} }
#[inline]
pub fn is_default_graph(&self) -> bool { pub fn is_default_graph(&self) -> bool {
self.as_ref().is_default_graph() self.as_ref().is_default_graph()
} }
#[inline]
pub fn as_ref(&self) -> GraphNameRef<'_> { pub fn as_ref(&self) -> GraphNameRef<'_> {
match self { match self {
Self::NamedNode(node) => GraphNameRef::NamedNode(node.as_ref()), Self::NamedNode(node) => GraphNameRef::NamedNode(node.as_ref()),
@ -542,36 +605,42 @@ impl GraphName {
} }
impl fmt::Display for GraphName { impl fmt::Display for GraphName {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.as_ref().fmt(f) self.as_ref().fmt(f)
} }
} }
impl From<NamedNode> for GraphName { impl From<NamedNode> for GraphName {
#[inline]
fn from(node: NamedNode) -> Self { fn from(node: NamedNode) -> Self {
GraphName::NamedNode(node) GraphName::NamedNode(node)
} }
} }
impl From<NamedNodeRef<'_>> for GraphName { impl From<NamedNodeRef<'_>> for GraphName {
#[inline]
fn from(node: NamedNodeRef<'_>) -> Self { fn from(node: NamedNodeRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
} }
impl From<BlankNode> for GraphName { impl From<BlankNode> for GraphName {
#[inline]
fn from(node: BlankNode) -> Self { fn from(node: BlankNode) -> Self {
GraphName::BlankNode(node) GraphName::BlankNode(node)
} }
} }
impl From<BlankNodeRef<'_>> for GraphName { impl From<BlankNodeRef<'_>> for GraphName {
#[inline]
fn from(node: BlankNodeRef<'_>) -> Self { fn from(node: BlankNodeRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
} }
impl From<NamedOrBlankNode> for GraphName { impl From<NamedOrBlankNode> for GraphName {
#[inline]
fn from(node: NamedOrBlankNode) -> Self { fn from(node: NamedOrBlankNode) -> Self {
match node { match node {
NamedOrBlankNode::NamedNode(node) => node.into(), NamedOrBlankNode::NamedNode(node) => node.into(),
@ -581,12 +650,14 @@ impl From<NamedOrBlankNode> for GraphName {
} }
impl From<NamedOrBlankNodeRef<'_>> for GraphName { impl From<NamedOrBlankNodeRef<'_>> for GraphName {
#[inline]
fn from(node: NamedOrBlankNodeRef<'_>) -> Self { fn from(node: NamedOrBlankNodeRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
} }
impl From<Option<NamedOrBlankNode>> for GraphName { impl From<Option<NamedOrBlankNode>> for GraphName {
#[inline]
fn from(name: Option<NamedOrBlankNode>) -> Self { fn from(name: Option<NamedOrBlankNode>) -> Self {
if let Some(node) = name { if let Some(node) = name {
node.into() node.into()
@ -597,6 +668,7 @@ impl From<Option<NamedOrBlankNode>> for GraphName {
} }
impl From<GraphName> for Option<NamedOrBlankNode> { impl From<GraphName> for Option<NamedOrBlankNode> {
#[inline]
fn from(name: GraphName) -> Self { fn from(name: GraphName) -> Self {
match name { match name {
GraphName::NamedNode(node) => Some(node.into()), GraphName::NamedNode(node) => Some(node.into()),
@ -616,6 +688,7 @@ pub enum GraphNameRef<'a> {
} }
impl<'a> GraphNameRef<'a> { impl<'a> GraphNameRef<'a> {
#[inline]
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
match self { match self {
GraphNameRef::NamedNode(_) => true, GraphNameRef::NamedNode(_) => true,
@ -623,6 +696,7 @@ impl<'a> GraphNameRef<'a> {
} }
} }
#[inline]
pub fn is_blank_node(&self) -> bool { pub fn is_blank_node(&self) -> bool {
match self { match self {
GraphNameRef::BlankNode(_) => true, GraphNameRef::BlankNode(_) => true,
@ -630,6 +704,7 @@ impl<'a> GraphNameRef<'a> {
} }
} }
#[inline]
pub fn is_default_graph(&self) -> bool { pub fn is_default_graph(&self) -> bool {
match self { match self {
GraphNameRef::DefaultGraph => true, GraphNameRef::DefaultGraph => true,
@ -637,6 +712,7 @@ impl<'a> GraphNameRef<'a> {
} }
} }
#[inline]
pub fn into_owned(self) -> GraphName { pub fn into_owned(self) -> GraphName {
match self { match self {
Self::NamedNode(node) => GraphName::NamedNode(node.into_owned()), Self::NamedNode(node) => GraphName::NamedNode(node.into_owned()),
@ -647,6 +723,7 @@ impl<'a> GraphNameRef<'a> {
} }
impl fmt::Display for GraphNameRef<'_> { impl fmt::Display for GraphNameRef<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::NamedNode(node) => node.fmt(f), Self::NamedNode(node) => node.fmt(f),
@ -657,30 +734,35 @@ impl fmt::Display for GraphNameRef<'_> {
} }
impl<'a> From<NamedNodeRef<'a>> for GraphNameRef<'a> { impl<'a> From<NamedNodeRef<'a>> for GraphNameRef<'a> {
#[inline]
fn from(node: NamedNodeRef<'a>) -> Self { fn from(node: NamedNodeRef<'a>) -> Self {
Self::NamedNode(node) Self::NamedNode(node)
} }
} }
impl<'a> From<&'a NamedNode> for GraphNameRef<'a> { impl<'a> From<&'a NamedNode> for GraphNameRef<'a> {
#[inline]
fn from(node: &'a NamedNode) -> Self { fn from(node: &'a NamedNode) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
impl<'a> From<BlankNodeRef<'a>> for GraphNameRef<'a> { impl<'a> From<BlankNodeRef<'a>> for GraphNameRef<'a> {
#[inline]
fn from(node: BlankNodeRef<'a>) -> Self { fn from(node: BlankNodeRef<'a>) -> Self {
Self::BlankNode(node) Self::BlankNode(node)
} }
} }
impl<'a> From<&'a BlankNode> for GraphNameRef<'a> { impl<'a> From<&'a BlankNode> for GraphNameRef<'a> {
#[inline]
fn from(node: &'a BlankNode) -> Self { fn from(node: &'a BlankNode) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
impl<'a> From<NamedOrBlankNodeRef<'a>> for GraphNameRef<'a> { impl<'a> From<NamedOrBlankNodeRef<'a>> for GraphNameRef<'a> {
#[inline]
fn from(node: NamedOrBlankNodeRef<'a>) -> Self { fn from(node: NamedOrBlankNodeRef<'a>) -> Self {
match node { match node {
NamedOrBlankNodeRef::NamedNode(node) => node.into(), NamedOrBlankNodeRef::NamedNode(node) => node.into(),
@ -690,24 +772,28 @@ impl<'a> From<NamedOrBlankNodeRef<'a>> for GraphNameRef<'a> {
} }
impl<'a> From<&'a NamedOrBlankNode> for GraphNameRef<'a> { impl<'a> From<&'a NamedOrBlankNode> for GraphNameRef<'a> {
#[inline]
fn from(node: &'a NamedOrBlankNode) -> Self { fn from(node: &'a NamedOrBlankNode) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
impl<'a> From<&'a GraphName> for GraphNameRef<'a> { impl<'a> From<&'a GraphName> for GraphNameRef<'a> {
#[inline]
fn from(node: &'a GraphName) -> Self { fn from(node: &'a GraphName) -> Self {
node.as_ref() node.as_ref()
} }
} }
impl<'a> From<GraphNameRef<'a>> for GraphName { impl<'a> From<GraphNameRef<'a>> for GraphName {
#[inline]
fn from(node: GraphNameRef<'a>) -> Self { fn from(node: GraphNameRef<'a>) -> Self {
node.into_owned() node.into_owned()
} }
} }
impl<'a> From<Option<NamedOrBlankNodeRef<'a>>> for GraphNameRef<'a> { impl<'a> From<Option<NamedOrBlankNodeRef<'a>>> for GraphNameRef<'a> {
#[inline]
fn from(name: Option<NamedOrBlankNodeRef<'a>>) -> Self { fn from(name: Option<NamedOrBlankNodeRef<'a>>) -> Self {
if let Some(node) = name { if let Some(node) = name {
node.into() node.into()
@ -718,6 +804,7 @@ impl<'a> From<Option<NamedOrBlankNodeRef<'a>>> for GraphNameRef<'a> {
} }
impl<'a> From<GraphNameRef<'a>> for Option<NamedOrBlankNodeRef<'a>> { impl<'a> From<GraphNameRef<'a>> for Option<NamedOrBlankNodeRef<'a>> {
#[inline]
fn from(name: GraphNameRef<'a>) -> Self { fn from(name: GraphNameRef<'a>) -> Self {
match name { match name {
GraphNameRef::NamedNode(node) => Some(node.into()), GraphNameRef::NamedNode(node) => Some(node.into()),
@ -728,6 +815,7 @@ impl<'a> From<GraphNameRef<'a>> for Option<NamedOrBlankNodeRef<'a>> {
} }
impl<'a> From<GraphNameRef<'a>> for Option<rio::NamedOrBlankNode<'a>> { impl<'a> From<GraphNameRef<'a>> for Option<rio::NamedOrBlankNode<'a>> {
#[inline]
fn from(name: GraphNameRef<'a>) -> Self { fn from(name: GraphNameRef<'a>) -> Self {
match name { match name {
GraphNameRef::NamedNode(node) => Some(rio::NamedNode::from(node).into()), GraphNameRef::NamedNode(node) => Some(rio::NamedNode::from(node).into()),
@ -755,6 +843,7 @@ pub struct Quad {
impl Quad { impl Quad {
/// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset)
#[inline]
pub fn new( pub fn new(
subject: impl Into<NamedOrBlankNode>, subject: impl Into<NamedOrBlankNode>,
predicate: impl Into<NamedNode>, predicate: impl Into<NamedNode>,
@ -810,6 +899,7 @@ impl Quad {
} }
#[deprecated(note = "Use `Triple::from` instead")] #[deprecated(note = "Use `Triple::from` instead")]
#[inline]
pub fn into_triple(self) -> Triple { pub fn into_triple(self) -> Triple {
Triple::new(self.subject, self.predicate, self.object) Triple::new(self.subject, self.predicate, self.object)
} }
@ -819,6 +909,7 @@ impl Quad {
(self.subject, self.predicate, self.object, self.graph_name) (self.subject, self.predicate, self.object, self.graph_name)
} }
#[inline]
pub fn as_ref(&self) -> QuadRef<'_> { pub fn as_ref(&self) -> QuadRef<'_> {
QuadRef { QuadRef {
subject: self.subject.as_ref(), subject: self.subject.as_ref(),
@ -830,12 +921,14 @@ impl Quad {
} }
impl fmt::Display for Quad { impl fmt::Display for Quad {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.as_ref().fmt(f) self.as_ref().fmt(f)
} }
} }
impl From<Quad> for Triple { impl From<Quad> for Triple {
#[inline]
fn from(quad: Quad) -> Self { fn from(quad: Quad) -> Self {
Self { Self {
subject: quad.subject, subject: quad.subject,
@ -863,6 +956,7 @@ pub struct QuadRef<'a> {
impl<'a> QuadRef<'a> { impl<'a> QuadRef<'a> {
/// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset)
#[inline]
pub fn new( pub fn new(
subject: impl Into<NamedOrBlankNodeRef<'a>>, subject: impl Into<NamedOrBlankNodeRef<'a>>,
predicate: impl Into<NamedNodeRef<'a>>, predicate: impl Into<NamedNodeRef<'a>>,
@ -877,6 +971,7 @@ impl<'a> QuadRef<'a> {
} }
} }
#[inline]
pub fn into_owned(self) -> Quad { pub fn into_owned(self) -> Quad {
Quad { Quad {
subject: self.subject.into_owned(), subject: self.subject.into_owned(),
@ -888,12 +983,14 @@ impl<'a> QuadRef<'a> {
} }
impl fmt::Display for QuadRef<'_> { impl fmt::Display for QuadRef<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
rio::Quad::from(*self).fmt(f) rio::Quad::from(*self).fmt(f)
} }
} }
impl<'a> From<QuadRef<'a>> for TripleRef<'a> { impl<'a> From<QuadRef<'a>> for TripleRef<'a> {
#[inline]
fn from(quad: QuadRef<'a>) -> Self { fn from(quad: QuadRef<'a>) -> Self {
Self { Self {
subject: quad.subject, subject: quad.subject,
@ -904,18 +1001,21 @@ impl<'a> From<QuadRef<'a>> for TripleRef<'a> {
} }
impl<'a> From<&'a Quad> for QuadRef<'a> { impl<'a> From<&'a Quad> for QuadRef<'a> {
#[inline]
fn from(quad: &'a Quad) -> Self { fn from(quad: &'a Quad) -> Self {
quad.as_ref() quad.as_ref()
} }
} }
impl<'a> From<QuadRef<'a>> for Quad { impl<'a> From<QuadRef<'a>> for Quad {
#[inline]
fn from(quad: QuadRef<'a>) -> Self { fn from(quad: QuadRef<'a>) -> Self {
quad.into_owned() quad.into_owned()
} }
} }
impl<'a> From<QuadRef<'a>> for rio::Quad<'a> { impl<'a> From<QuadRef<'a>> for rio::Quad<'a> {
#[inline]
fn from(quad: QuadRef<'a>) -> Self { fn from(quad: QuadRef<'a>) -> Self {
rio::Quad { rio::Quad {
subject: quad.subject.into(), subject: quad.subject.into(),

@ -107,6 +107,7 @@ impl QueryResult {
} }
impl From<QuerySolutionsIterator> for QueryResult { impl From<QuerySolutionsIterator> for QueryResult {
#[inline]
fn from(value: QuerySolutionsIterator) -> Self { fn from(value: QuerySolutionsIterator) -> Self {
QueryResult::Solutions(value) QueryResult::Solutions(value)
} }
@ -132,6 +133,7 @@ impl QueryResultFormat {
/// ///
/// assert_eq!(QueryResultFormat::Json.iri(), "http://www.w3.org/ns/formats/SPARQL_Results_JSON") /// assert_eq!(QueryResultFormat::Json.iri(), "http://www.w3.org/ns/formats/SPARQL_Results_JSON")
/// ``` /// ```
#[inline]
pub fn iri(self) -> &'static str { pub fn iri(self) -> &'static str {
match self { match self {
QueryResultFormat::Xml => "http://www.w3.org/ns/formats/SPARQL_Results_XML", QueryResultFormat::Xml => "http://www.w3.org/ns/formats/SPARQL_Results_XML",
@ -145,6 +147,7 @@ impl QueryResultFormat {
/// ///
/// assert_eq!(QueryResultFormat::Json.media_type(), "application/sparql-results+json") /// assert_eq!(QueryResultFormat::Json.media_type(), "application/sparql-results+json")
/// ``` /// ```
#[inline]
pub fn media_type(self) -> &'static str { pub fn media_type(self) -> &'static str {
match self { match self {
QueryResultFormat::Xml => "application/sparql-results+xml", QueryResultFormat::Xml => "application/sparql-results+xml",
@ -159,6 +162,7 @@ impl QueryResultFormat {
/// ///
/// assert_eq!(QueryResultFormat::Json.file_extension(), "srj") /// assert_eq!(QueryResultFormat::Json.file_extension(), "srj")
/// ``` /// ```
#[inline]
pub fn file_extension(self) -> &'static str { pub fn file_extension(self) -> &'static str {
match self { match self {
QueryResultFormat::Xml => "srx", QueryResultFormat::Xml => "srx",
@ -252,6 +256,7 @@ impl QuerySolutionsIterator {
/// } /// }
/// # Result::<_,Box<dyn std::error::Error>>::Ok(()) /// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ``` /// ```
#[inline]
pub fn variables(&self) -> &[Variable] { pub fn variables(&self) -> &[Variable] {
&*self.variables &*self.variables
} }
@ -277,6 +282,7 @@ impl QuerySolutionsIterator {
impl Iterator for QuerySolutionsIterator { impl Iterator for QuerySolutionsIterator {
type Item = Result<QuerySolution, EvaluationError>; type Item = Result<QuerySolution, EvaluationError>;
#[inline]
fn next(&mut self) -> Option<Result<QuerySolution, EvaluationError>> { fn next(&mut self) -> Option<Result<QuerySolution, EvaluationError>> {
Some(self.iter.next()?.map(|values| QuerySolution { Some(self.iter.next()?.map(|values| QuerySolution {
values, values,
@ -284,6 +290,7 @@ impl Iterator for QuerySolutionsIterator {
})) }))
} }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint() self.iter.size_hint()
} }
@ -304,21 +311,25 @@ impl QuerySolution {
/// let foo = solution.get("foo"); // Get the value of the variable ?foo if it exists /// let foo = solution.get("foo"); // Get the value of the variable ?foo if it exists
/// let first = solution.get(1); // Get the value of the second column if it exists /// let first = solution.get(1); // Get the value of the second column if it exists
/// ``` /// ```
#[inline]
pub fn get(&self, index: impl VariableSolutionIndex) -> Option<&Term> { pub fn get(&self, index: impl VariableSolutionIndex) -> Option<&Term> {
self.values.get(index.index(self)?).and_then(|e| e.as_ref()) self.values.get(index.index(self)?).and_then(|e| e.as_ref())
} }
/// The number of variables which are bind /// The number of variables which are bind
#[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.values.len() self.values.len()
} }
/// Is this binding empty? /// Is this binding empty?
#[inline]
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.values.is_empty() self.values.is_empty()
} }
/// Returns an iterator over bound variables /// Returns an iterator over bound variables
#[inline]
pub fn iter(&self) -> impl Iterator<Item = (&Variable, &Term)> { pub fn iter(&self) -> impl Iterator<Item = (&Variable, &Term)> {
self.values self.values
.iter() .iter()
@ -339,24 +350,28 @@ pub trait VariableSolutionIndex {
} }
impl VariableSolutionIndex for usize { impl VariableSolutionIndex for usize {
#[inline]
fn index(self, _: &QuerySolution) -> Option<usize> { fn index(self, _: &QuerySolution) -> Option<usize> {
Some(self) Some(self)
} }
} }
impl VariableSolutionIndex for &str { impl VariableSolutionIndex for &str {
#[inline]
fn index(self, solution: &QuerySolution) -> Option<usize> { fn index(self, solution: &QuerySolution) -> Option<usize> {
solution.variables.iter().position(|v| v.as_str() == self) solution.variables.iter().position(|v| v.as_str() == self)
} }
} }
impl VariableSolutionIndex for &Variable { impl VariableSolutionIndex for &Variable {
#[inline]
fn index(self, solution: &QuerySolution) -> Option<usize> { fn index(self, solution: &QuerySolution) -> Option<usize> {
solution.variables.iter().position(|v| v == self) solution.variables.iter().position(|v| v == self)
} }
} }
impl VariableSolutionIndex for Variable { impl VariableSolutionIndex for Variable {
#[inline]
fn index(self, solution: &QuerySolution) -> Option<usize> { fn index(self, solution: &QuerySolution) -> Option<usize> {
(&self).index(solution) (&self).index(solution)
} }
@ -383,14 +398,17 @@ pub struct QueryTriplesIterator {
impl Iterator for QueryTriplesIterator { impl Iterator for QueryTriplesIterator {
type Item = Result<Triple, EvaluationError>; type Item = Result<Triple, EvaluationError>;
#[inline]
fn next(&mut self) -> Option<Result<Triple, EvaluationError>> { fn next(&mut self) -> Option<Result<Triple, EvaluationError>> {
self.iter.next() self.iter.next()
} }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint() self.iter.size_hint()
} }
#[inline]
fn fold<Acc, G>(self, init: Acc, mut g: G) -> Acc fn fold<Acc, G>(self, init: Acc, mut g: G) -> Acc
where where
G: FnMut(Acc, Self::Item) -> Acc, G: FnMut(Acc, Self::Item) -> Acc,
@ -415,10 +433,12 @@ pub struct Variable {
} }
impl Variable { impl Variable {
#[inline]
pub fn new(name: impl Into<String>) -> Self { pub fn new(name: impl Into<String>) -> Self {
Variable { name: name.into() } Variable { name: name.into() }
} }
#[inline]
pub fn as_str(&self) -> &str { pub fn as_str(&self) -> &str {
&self.name &self.name
} }
@ -428,16 +448,19 @@ impl Variable {
Ok(self.as_str()) Ok(self.as_str())
} }
#[inline]
pub fn into_string(self) -> String { pub fn into_string(self) -> String {
self.name self.name
} }
#[inline]
pub(crate) fn new_random() -> Self { pub(crate) fn new_random() -> Self {
Self::new(format!("{:x}", random::<u128>())) Self::new(format!("{:x}", random::<u128>()))
} }
} }
impl fmt::Display for Variable { impl fmt::Display for Variable {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "?{}", self.name) write!(f, "?{}", self.name)
} }

@ -48,7 +48,7 @@ impl PyMemoryStore {
/// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>] /// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
#[text_signature = "($self, quad)"] #[text_signature = "($self, quad)"]
fn add(&self, quad: PyQuad) { fn add(&self, quad: PyQuad) {
self.inner.insert(quad.into()); self.inner.insert(quad);
} }
/// Removes a quad from the store /// Removes a quad from the store

Loading…
Cancel
Save