TokioAsyncReaderQuadParser

Struct TokioAsyncReaderQuadParser 

Source
pub struct TokioAsyncReaderQuadParser<R: AsyncRead + Unpin> { /* private fields */ }
Available on crate feature async-tokio only.
Expand description

Parses an RDF file from a Tokio AsyncRead implementation.

Can be built using RdfParser::for_tokio_async_reader.

Reads are buffered.

use oxrdfio::{RdfFormat, RdfParser};

let file = "<http://example.com/s> <http://example.com/p> <http://example.com/o> .";

let mut parser =
    RdfParser::from_format(RdfFormat::NTriples).for_tokio_async_reader(file.as_bytes());
if let Some(quad) = parser.next().await {
    assert_eq!(quad?.subject.to_string(), "<http://example.com/s>");
}

Implementations§

Source§

impl<R: AsyncRead + Unpin> TokioAsyncReaderQuadParser<R>

Source

pub async fn next(&mut self) -> Option<Result<Quad, RdfParseError>>

Source

pub fn prefixes(&self) -> PrefixesIter<'_>

The list of IRI prefixes considered at the current step of the parsing.

This method returns (prefix name, prefix value) tuples. It is empty at the beginning of the parsing and gets updated when prefixes are encountered. It should be full at the end of the parsing (but if a prefix is overridden, only the latest version will be returned).

An empty iterator is return if the format does not support prefixes.

use oxrdfio::{RdfFormat, RdfParser};

let file = r#"@base <http://example.com/> .
@prefix schema: <http://schema.org/> .
<foo> a schema:Person ;
    schema:name "Foo" ."#;

let mut parser =
    RdfParser::from_format(RdfFormat::Turtle).for_tokio_async_reader(file.as_bytes());
assert_eq!(parser.prefixes().collect::<Vec<_>>(), []); // No prefix at the beginning

parser.next().await.unwrap()?; // We read the first triple
assert_eq!(
    parser.prefixes().collect::<Vec<_>>(),
    [("schema", "http://schema.org/")]
); // There are now prefixes
//
Source

pub fn base_iri(&self) -> Option<&str>

The base IRI considered at the current step of the parsing.

None is returned if no base IRI is set or the format does not support base IRIs.

use oxrdfio::{RdfFormat, RdfParser};

let file = r#"@base <http://example.com/> .
@prefix schema: <http://schema.org/> .
<foo> a schema:Person ;
    schema:name "Foo" ."#;

let mut parser =
    RdfParser::from_format(RdfFormat::Turtle).for_tokio_async_reader(file.as_bytes());
assert!(parser.base_iri().is_none()); // No base IRI at the beginning

parser.next().await.unwrap()?; // We read the first triple
assert_eq!(parser.base_iri(), Some("http://example.com/")); // There is now a base IRI
//

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V