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>
impl<R: AsyncRead + Unpin> TokioAsyncReaderQuadParser<R>
pub async fn next(&mut self) -> Option<Result<Quad, RdfParseError>>
Sourcepub fn prefixes(&self) -> PrefixesIter<'_>
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
//Sourcepub fn base_iri(&self) -> Option<&str>
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§
impl<R> Freeze for TokioAsyncReaderQuadParser<R>where
R: Freeze,
impl<R> RefUnwindSafe for TokioAsyncReaderQuadParser<R>where
R: RefUnwindSafe,
impl<R> Send for TokioAsyncReaderQuadParser<R>where
R: Send,
impl<R> Sync for TokioAsyncReaderQuadParser<R>where
R: Sync,
impl<R> Unpin for TokioAsyncReaderQuadParser<R>
impl<R> UnwindSafe for TokioAsyncReaderQuadParser<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more