Simplify complex strings with raw literals, readme fix

Also add a minor debugging python statement to linter
pull/739/head
Yuri Astrakhan 11 months ago committed by Thomas Tanon
parent d4bfcd3b24
commit 51941c0dc5
  1. 40
      cli/src/main.rs
  2. 6
      lib/oxrdf/src/literal.rs
  3. 32
      lib/oxrdfxml/README.md
  4. 60
      lib/oxrdfxml/src/parser.rs
  5. 54
      lib/oxttl/src/n3.rs
  6. 30
      lib/oxttl/src/nquads.rs
  7. 32
      lib/oxttl/src/ntriples.rs
  8. 54
      lib/oxttl/src/trig.rs
  9. 54
      lib/oxttl/src/turtle.rs
  10. 10
      lib/sparesults/src/parser.rs
  11. 16
      lib/sparesults/src/serializer.rs
  12. 2
      lib/src/sparql/model.rs
  13. 4
      lib/src/sparql/results.rs

@ -2354,7 +2354,7 @@ mod tests {
.build(); .build();
ServerTest::new()?.test_body( ServerTest::new()?.test_body(
request, request,
"{\"head\":{\"vars\":[\"s\",\"p\",\"o\"]},\"results\":{\"bindings\":[]}}", r#"{"head":{"vars":["s","p","o"]},"results":{"bindings":[]}}"#,
) )
} }
@ -2369,7 +2369,7 @@ mod tests {
.build(); .build();
ServerTest::new()?.test_body( ServerTest::new()?.test_body(
request, request,
"{\"head\":{\"vars\":[\"s\",\"p\",\"o\"]},\"results\":{\"bindings\":[]}}", r#"{"head":{"vars":["s","p","o"]},"results":{"bindings":[]}}"#,
) )
} }
@ -2387,7 +2387,7 @@ mod tests {
.build(); .build();
ServerTest::new()?.test_body( ServerTest::new()?.test_body(
request, request,
"{\"head\":{\"vars\":[\"s\",\"p\",\"o\"]},\"results\":{\"bindings\":[]}}", r#"{"head":{"vars":["s","p","o"]},"results":{"bindings":[]}}"#,
) )
} }
@ -2414,7 +2414,7 @@ mod tests {
.build(); .build();
ServerTest::new()?.test_body( ServerTest::new()?.test_body(
request, request,
"{\"head\":{\"vars\":[\"s\",\"p\",\"o\"]},\"results\":{\"bindings\":[]}}", r#"{"head":{"vars":["s","p","o"]},"results":{"bindings":[]}}"#,
) )
} }
@ -2429,7 +2429,7 @@ mod tests {
.build(); .build();
ServerTest::new()?.test_body( ServerTest::new()?.test_body(
request, request,
"{\"head\":{\"vars\":[\"s\",\"p\",\"o\"]},\"results\":{\"bindings\":[]}}", r#"{"head":{"vars":["s","p","o"]},"results":{"bindings":[]}}"#,
) )
} }
#[test] #[test]
@ -2679,16 +2679,16 @@ mod tests {
let request = Request::builder(Method::PUT, "http://localhost/store/person/1.ttl".parse()?) let request = Request::builder(Method::PUT, "http://localhost/store/person/1.ttl".parse()?)
.with_header(HeaderName::CONTENT_TYPE, "text/turtle; charset=utf-8")? .with_header(HeaderName::CONTENT_TYPE, "text/turtle; charset=utf-8")?
.with_body( .with_body(
" r#"
@prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix v: <http://www.w3.org/2006/vcard/ns#> . @prefix v: <http://www.w3.org/2006/vcard/ns#> .
<http://$HOST$/$GRAPHSTORE$/person/1> a foaf:Person; <http://$HOST$/$GRAPHSTORE$/person/1> a foaf:Person;
foaf:businessCard [ foaf:businessCard [
a v:VCard; a v:VCard;
v:fn \"John Doe\" v:fn "John Doe"
]. ].
", "#,
); );
server.test_status(request, Status::CREATED)?; server.test_status(request, Status::CREATED)?;
@ -2717,16 +2717,16 @@ mod tests {
let request = Request::builder(Method::PUT, "http://localhost/store/person/1.ttl".parse()?) let request = Request::builder(Method::PUT, "http://localhost/store/person/1.ttl".parse()?)
.with_header(HeaderName::CONTENT_TYPE, "text/turtle; charset=utf-8")? .with_header(HeaderName::CONTENT_TYPE, "text/turtle; charset=utf-8")?
.with_body( .with_body(
" r#"
@prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix v: <http://www.w3.org/2006/vcard/ns#> . @prefix v: <http://www.w3.org/2006/vcard/ns#> .
<http://$HOST$/$GRAPHSTORE$/person/1> a foaf:Person; <http://$HOST$/$GRAPHSTORE$/person/1> a foaf:Person;
foaf:businessCard [ foaf:businessCard [
a v:VCard; a v:VCard;
v:fn \"Jane Doe\" v:fn "Jane Doe"
]. ].
", "#,
); );
server.test_status(request, Status::NO_CONTENT)?; server.test_status(request, Status::NO_CONTENT)?;
@ -2740,16 +2740,16 @@ mod tests {
let request = Request::builder(Method::PUT, "http://localhost/store?default".parse()?) let request = Request::builder(Method::PUT, "http://localhost/store?default".parse()?)
.with_header(HeaderName::CONTENT_TYPE, "text/turtle; charset=utf-8")? .with_header(HeaderName::CONTENT_TYPE, "text/turtle; charset=utf-8")?
.with_body( .with_body(
" r#"
@prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix v: <http://www.w3.org/2006/vcard/ns#> . @prefix v: <http://www.w3.org/2006/vcard/ns#> .
[] a foaf:Person; [] a foaf:Person;
foaf:businessCard [ foaf:businessCard [
a v:VCard; a v:VCard;
v:given-name \"Alice\" v:given-name "Alice"
] . ] .
", "#,
); );
server.test_status(request, Status::NO_CONTENT)?; // The default graph always exists in Oxigraph server.test_status(request, Status::NO_CONTENT)?; // The default graph always exists in Oxigraph
@ -2781,16 +2781,16 @@ mod tests {
let request = Request::builder(Method::PUT, "http://localhost/store/person/2.ttl".parse()?) let request = Request::builder(Method::PUT, "http://localhost/store/person/2.ttl".parse()?)
.with_header(HeaderName::CONTENT_TYPE, "text/turtle; charset=utf-8")? .with_header(HeaderName::CONTENT_TYPE, "text/turtle; charset=utf-8")?
.with_body( .with_body(
" r#"
@prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix v: <http://www.w3.org/2006/vcard/ns#> . @prefix v: <http://www.w3.org/2006/vcard/ns#> .
[] a foaf:Person; [] a foaf:Person;
foaf:businessCard [ foaf:businessCard [
a v:VCard; a v:VCard;
v:given-name \"Alice\" v:given-name "Alice"
] . ] .
", "#,
); );
server.test_status(request, Status::NO_CONTENT)?; server.test_status(request, Status::NO_CONTENT)?;
@ -2839,16 +2839,16 @@ mod tests {
let request = Request::builder(Method::POST, "http://localhost/store".parse()?) let request = Request::builder(Method::POST, "http://localhost/store".parse()?)
.with_header(HeaderName::CONTENT_TYPE, "text/turtle; charset=utf-8")? .with_header(HeaderName::CONTENT_TYPE, "text/turtle; charset=utf-8")?
.with_body( .with_body(
" r#"
@prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix v: <http://www.w3.org/2006/vcard/ns#> . @prefix v: <http://www.w3.org/2006/vcard/ns#> .
[] a foaf:Person; [] a foaf:Person;
foaf:businessCard [ foaf:businessCard [
a v:VCard; a v:VCard;
v:given-name \"Alice\" v:given-name "Alice"
] . ] .
", "#,
); );
let response = server.exec(request); let response = server.exec(request);
assert_eq!(response.status(), Status::CREATED); assert_eq!(response.status(), Status::CREATED);

@ -24,12 +24,12 @@ use std::option::Option;
/// ); /// );
/// ///
/// assert_eq!( /// assert_eq!(
/// "\"1999-01-01\"^^<http://www.w3.org/2001/XMLSchema#date>", /// r#""1999-01-01"^^<http://www.w3.org/2001/XMLSchema#date>"#,
/// Literal::new_typed_literal("1999-01-01", xsd::DATE).to_string() /// Literal::new_typed_literal("1999-01-01", xsd::DATE).to_string()
/// ); /// );
/// ///
/// assert_eq!( /// assert_eq!(
/// "\"foo\"@en", /// r#""foo"@en"#,
/// Literal::new_language_tagged_literal("foo", "en")?.to_string() /// Literal::new_language_tagged_literal("foo", "en")?.to_string()
/// ); /// );
/// # Result::<(), LanguageTagParseError>::Ok(()) /// # Result::<(), LanguageTagParseError>::Ok(())
@ -436,7 +436,7 @@ impl From<DayTimeDuration> for Literal {
/// ); /// );
/// ///
/// assert_eq!( /// assert_eq!(
/// "\"1999-01-01\"^^<http://www.w3.org/2001/XMLSchema#date>", /// r#""1999-01-01"^^<http://www.w3.org/2001/XMLSchema#date>"#,
/// LiteralRef::new_typed_literal("1999-01-01", xsd::DATE).to_string() /// LiteralRef::new_typed_literal("1999-01-01", xsd::DATE).to_string()
/// ); /// );
/// ``` /// ```

@ -12,31 +12,33 @@ OxRdfXml is a parser and serializer for [RDF/XML](https://www.w3.org/TR/rdf-synt
The entry points of this library are the two [`RdfXmlParser`] and [`RdfXmlSerializer`] structs. The entry points of this library are the two [`RdfXmlParser`] and [`RdfXmlSerializer`] structs.
Usage example counting the number of people in a RDF/XML file: Usage example counting the number of people in a RDF/XML file:
```rust ```rust
use oxrdf::{NamedNodeRef, vocab::rdf}; use oxrdf::{NamedNodeRef, vocab::rdf};
use oxrdfxml::RdfXmlParser; use oxrdfxml::RdfXmlParser;
let file = b"<?xml version=\"1.0\"?> fn main() {
<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:schema=\"http://schema.org/\"> let file = br#"<?xml version="1.0"?>
<rdf:Description rdf:about=\"http://example.com/foo\"> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:schema="http://schema.org/">
<rdf:type rdf:resource=\"http://schema.org/Person\" /> <rdf:Description rdf:about="http://example.com/foo">
<rdf:type rdf:resource="http://schema.org/Person" />
<schema:name>Foo</schema:name> <schema:name>Foo</schema:name>
</rdf:Description> </rdf:Description>
<schema:Person rdf:about=\"http://example.com/bar\" schema:name=\"Bar\" /> <schema:Person rdf:about="http://example.com/bar" schema:name="Bar" />
</rdf:RDF>"; </rdf:RDF>"#;
let schema_person = NamedNodeRef::new("http://schema.org/Person").unwrap(); let schema_person = NamedNodeRef::new("http://schema.org/Person").unwrap();
let mut count = 0; let mut count = 0;
for triple in RdfXmlParser::new().parse_read(file.as_ref()) { for triple in RdfXmlParser::new().parse_read(file.as_ref()) {
let triple = triple.unwrap(); let triple = triple.unwrap();
if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
count += 1; count += 1;
}
} }
assert_eq!(2, count);
} }
assert_eq!(2, count);
``` ```
## License ## License
This project is licensed under either of This project is licensed under either of

@ -29,14 +29,14 @@ use tokio::io::{AsyncRead, BufReader as AsyncBufReader};
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxrdfxml::RdfXmlParser; /// use oxrdfxml::RdfXmlParser;
/// ///
/// let file = b"<?xml version=\"1.0\"?> /// let file = br#"<?xml version="1.0"?>
/// <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:schema=\"http://schema.org/\"> /// <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:schema="http://schema.org/">
/// <rdf:Description rdf:about=\"http://example.com/foo\"> /// <rdf:Description rdf:about="http://example.com/foo">
/// <rdf:type rdf:resource=\"http://schema.org/Person\" /> /// <rdf:type rdf:resource="http://schema.org/Person" />
/// <schema:name>Foo</schema:name> /// <schema:name>Foo</schema:name>
/// </rdf:Description> /// </rdf:Description>
/// <schema:Person rdf:about=\"http://example.com/bar\" schema:name=\"Bar\" /> /// <schema:Person rdf:about="http://example.com/bar" schema:name="Bar" />
/// </rdf:RDF>"; /// </rdf:RDF>"#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -87,14 +87,14 @@ impl RdfXmlParser {
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxrdfxml::RdfXmlParser; /// use oxrdfxml::RdfXmlParser;
/// ///
/// let file = b"<?xml version=\"1.0\"?> /// let file = br#"<?xml version="1.0"?>
/// <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:schema=\"http://schema.org/\"> /// <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:schema="http://schema.org/">
/// <rdf:Description rdf:about=\"http://example.com/foo\"> /// <rdf:Description rdf:about="http://example.com/foo">
/// <rdf:type rdf:resource=\"http://schema.org/Person\" /> /// <rdf:type rdf:resource="http://schema.org/Person" />
/// <schema:name>Foo</schema:name> /// <schema:name>Foo</schema:name>
/// </rdf:Description> /// </rdf:Description>
/// <schema:Person rdf:about=\"http://example.com/bar\" schema:name=\"Bar\" /> /// <schema:Person rdf:about="http://example.com/bar" schema:name="Bar" />
/// </rdf:RDF>"; /// </rdf:RDF>"#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -124,14 +124,14 @@ impl RdfXmlParser {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxrdfxml::ParseError> { /// # async fn main() -> Result<(), oxrdfxml::ParseError> {
/// let file = b"<?xml version=\"1.0\"?> /// let file = br#"<?xml version="1.0"?>
/// <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:schema=\"http://schema.org/\"> /// <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:schema="http://schema.org/">
/// <rdf:Description rdf:about=\"http://example.com/foo\"> /// <rdf:Description rdf:about="http://example.com/foo">
/// <rdf:type rdf:resource=\"http://schema.org/Person\" /> /// <rdf:type rdf:resource="http://schema.org/Person" />
/// <schema:name>Foo</schema:name> /// <schema:name>Foo</schema:name>
/// </rdf:Description> /// </rdf:Description>
/// <schema:Person rdf:about=\"http://example.com/bar\" schema:name=\"Bar\" /> /// <schema:Person rdf:about="http://example.com/bar" schema:name="Bar" />
/// </rdf:RDF>"; /// </rdf:RDF>"#;
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
@ -182,14 +182,14 @@ impl RdfXmlParser {
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxrdfxml::RdfXmlParser; /// use oxrdfxml::RdfXmlParser;
/// ///
/// let file = b"<?xml version=\"1.0\"?> /// let file = br#"<?xml version="1.0"?>
/// <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:schema=\"http://schema.org/\"> /// <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:schema="http://schema.org/">
/// <rdf:Description rdf:about=\"http://example.com/foo\"> /// <rdf:Description rdf:about="http://example.com/foo">
/// <rdf:type rdf:resource=\"http://schema.org/Person\" /> /// <rdf:type rdf:resource="http://schema.org/Person" />
/// <schema:name>Foo</schema:name> /// <schema:name>Foo</schema:name>
/// </rdf:Description> /// </rdf:Description>
/// <schema:Person rdf:about=\"http://example.com/bar\" schema:name=\"Bar\" /> /// <schema:Person rdf:about="http://example.com/bar" schema:name="Bar" />
/// </rdf:RDF>"; /// </rdf:RDF>"#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -251,14 +251,14 @@ impl<R: Read> FromReadRdfXmlReader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxrdfxml::ParseError> { /// # async fn main() -> Result<(), oxrdfxml::ParseError> {
/// let file = b"<?xml version=\"1.0\"?> /// let file = br#"<?xml version="1.0"?>
/// <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:schema=\"http://schema.org/\"> /// <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:schema="http://schema.org/">
/// <rdf:Description rdf:about=\"http://example.com/foo\"> /// <rdf:Description rdf:about="http://example.com/foo">
/// <rdf:type rdf:resource=\"http://schema.org/Person\" /> /// <rdf:type rdf:resource="http://schema.org/Person" />
/// <schema:name>Foo</schema:name> /// <schema:name>Foo</schema:name>
/// </rdf:Description> /// </rdf:Description>
/// <schema:Person rdf:about=\"http://example.com/bar\" schema:name=\"Bar\" /> /// <schema:Person rdf:about="http://example.com/bar" schema:name="Bar" />
/// </rdf:RDF>"; /// </rdf:RDF>"#;
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;

@ -184,12 +184,12 @@ impl From<Quad> for N3Quad {
/// use oxrdf::{NamedNode, vocab::rdf}; /// use oxrdf::{NamedNode, vocab::rdf};
/// use oxttl::n3::{N3Parser, N3Term}; /// use oxttl::n3::{N3Parser, N3Term};
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned());
/// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?); /// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?);
@ -253,12 +253,12 @@ impl N3Parser {
/// use oxrdf::NamedNode; /// use oxrdf::NamedNode;
/// use oxttl::n3::{N3Parser, N3Term}; /// use oxttl::n3::{N3Parser, N3Term};
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let rdf_type = N3Term::NamedNode(NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?); /// let rdf_type = N3Term::NamedNode(NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?);
/// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?); /// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?);
@ -287,12 +287,12 @@ impl N3Parser {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned());
/// let schema_person = N3Term::NamedNode(NamedNode::new_unchecked("http://schema.org/Person")); /// let schema_person = N3Term::NamedNode(NamedNode::new_unchecked("http://schema.org/Person"));
@ -369,12 +369,12 @@ impl N3Parser {
/// use oxrdf::{NamedNode, vocab::rdf}; /// use oxrdf::{NamedNode, vocab::rdf};
/// use oxttl::n3::{N3Parser, N3Term}; /// use oxttl::n3::{N3Parser, N3Term};
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned());
/// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?); /// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?);
@ -403,10 +403,10 @@ impl<R: Read> FromReadN3Reader<R> {
/// ``` /// ```
/// use oxttl::N3Parser; /// use oxttl::N3Parser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = N3Parser::new().parse_read(file.as_ref()); /// let mut reader = N3Parser::new().parse_read(file.as_ref());
/// assert!(reader.prefixes().is_empty()); // No prefix at the beginning /// assert!(reader.prefixes().is_empty()); // No prefix at the beginning
@ -424,10 +424,10 @@ impl<R: Read> FromReadN3Reader<R> {
/// ``` /// ```
/// use oxttl::N3Parser; /// use oxttl::N3Parser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = N3Parser::new().parse_read(file.as_ref()); /// let mut reader = N3Parser::new().parse_read(file.as_ref());
/// assert!(reader.base_iri().is_none()); // No base at the beginning because none has been given to the parser. /// assert!(reader.base_iri().is_none()); // No base at the beginning because none has been given to the parser.
@ -464,12 +464,12 @@ impl<R: Read> Iterator for FromReadN3Reader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned());
/// let schema_person = N3Term::NamedNode(NamedNode::new_unchecked("http://schema.org/Person")); /// let schema_person = N3Term::NamedNode(NamedNode::new_unchecked("http://schema.org/Person"));
@ -509,10 +509,10 @@ impl<R: AsyncRead + Unpin> FromTokioAsyncReadN3Reader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = N3Parser::new().parse_tokio_async_read(file.as_ref()); /// let mut reader = N3Parser::new().parse_tokio_async_read(file.as_ref());
/// assert!(reader.prefixes().is_empty()); // No prefix at the beginning /// assert!(reader.prefixes().is_empty()); // No prefix at the beginning
@ -533,10 +533,10 @@ impl<R: AsyncRead + Unpin> FromTokioAsyncReadN3Reader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = N3Parser::new().parse_tokio_async_read(file.as_ref()); /// let mut reader = N3Parser::new().parse_tokio_async_read(file.as_ref());
/// assert!(reader.base_iri().is_none()); // No base IRI at the beginning /// assert!(reader.base_iri().is_none()); // No base IRI at the beginning
@ -633,10 +633,10 @@ impl LowLevelN3Reader {
/// ``` /// ```
/// use oxttl::N3Parser; /// use oxttl::N3Parser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = N3Parser::new().parse(); /// let mut reader = N3Parser::new().parse();
/// reader.extend_from_slice(file); /// reader.extend_from_slice(file);
@ -655,10 +655,10 @@ impl LowLevelN3Reader {
/// ``` /// ```
/// use oxttl::N3Parser; /// use oxttl::N3Parser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = N3Parser::new().parse(); /// let mut reader = N3Parser::new().parse();
/// reader.extend_from_slice(file); /// reader.extend_from_slice(file);

@ -19,10 +19,10 @@ use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::NQuadsParser; /// use oxttl::NQuadsParser;
/// ///
/// let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// let file = br#"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/foo> <http://schema.org/name> \"Foo\" . /// <http://example.com/foo> <http://schema.org/name> "Foo" .
/// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/bar> <http://schema.org/name> \"Bar\" ."; /// <http://example.com/bar> <http://schema.org/name> "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -76,10 +76,10 @@ impl NQuadsParser {
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::NQuadsParser; /// use oxttl::NQuadsParser;
/// ///
/// let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// let file = br#"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/foo> <http://schema.org/name> \"Foo\" . /// <http://example.com/foo> <http://schema.org/name> "Foo" .
/// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/bar> <http://schema.org/name> \"Bar\" ."; /// <http://example.com/bar> <http://schema.org/name> "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -107,10 +107,10 @@ impl NQuadsParser {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// let file = br#"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/foo> <http://schema.org/name> \"Foo\" . /// <http://example.com/foo> <http://schema.org/name> "Foo" .
/// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/bar> <http://schema.org/name> \"Bar\" ."; /// <http://example.com/bar> <http://schema.org/name> "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
@ -191,10 +191,10 @@ impl NQuadsParser {
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::NQuadsParser; /// use oxttl::NQuadsParser;
/// ///
/// let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// let file = br#"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/foo> <http://schema.org/name> \"Foo\" . /// <http://example.com/foo> <http://schema.org/name> "Foo" .
/// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/bar> <http://schema.org/name> \"Bar\" ."; /// <http://example.com/bar> <http://schema.org/name> "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -229,10 +229,10 @@ impl<R: Read> Iterator for FromReadNQuadsReader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// let file = br#"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/foo> <http://schema.org/name> \"Foo\" . /// <http://example.com/foo> <http://schema.org/name> "Foo" .
/// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/bar> <http://schema.org/name> \"Bar\" ."; /// <http://example.com/bar> <http://schema.org/name> "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;

@ -19,10 +19,10 @@ use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::NTriplesParser; /// use oxttl::NTriplesParser;
/// ///
/// let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// let file = br#"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/foo> <http://schema.org/name> \"Foo\" . /// <http://example.com/foo> <http://schema.org/name> "Foo" .
/// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/bar> <http://schema.org/name> \"Bar\" ."; /// <http://example.com/bar> <http://schema.org/name> "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -76,10 +76,10 @@ impl NTriplesParser {
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::NTriplesParser; /// use oxttl::NTriplesParser;
/// ///
/// let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// let file = br#"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/foo> <http://schema.org/name> \"Foo\" . /// <http://example.com/foo> <http://schema.org/name> "Foo" .
/// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/bar> <http://schema.org/name> \"Bar\" ."; /// <http://example.com/bar> <http://schema.org/name> "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -107,10 +107,10 @@ impl NTriplesParser {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// let file = br#"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/foo> <http://schema.org/name> \"Foo\" . /// <http://example.com/foo> <http://schema.org/name> "Foo" .
/// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/bar> <http://schema.org/name> \"Bar\" ."; /// <http://example.com/bar> <http://schema.org/name> "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
@ -191,10 +191,10 @@ impl NTriplesParser {
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::NTriplesParser; /// use oxttl::NTriplesParser;
/// ///
/// let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// let file = br#"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/foo> <http://schema.org/name> \"Foo\" . /// <http://example.com/foo> <http://schema.org/name> "Foo" .
/// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/bar> <http://schema.org/name> \"Bar\" ."; /// <http://example.com/bar> <http://schema.org/name> "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -229,10 +229,10 @@ impl<R: Read> Iterator for FromReadNTriplesReader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// let file = br#"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/foo> <http://schema.org/name> \"Foo\" . /// <http://example.com/foo> <http://schema.org/name> "Foo" .
/// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . /// <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
/// <http://example.com/bar> <http://schema.org/name> \"Bar\" ."; /// <http://example.com/bar> <http://schema.org/name> "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
@ -565,7 +565,7 @@ mod tests {
fn unchecked_parsing() { fn unchecked_parsing() {
let triples = NTriplesParser::new() let triples = NTriplesParser::new()
.unchecked() .unchecked()
.parse_read("<foo> <bar> \"baz\"@toolonglangtag .".as_bytes()) .parse_read(r#"<foo> <bar> "baz"@toolonglangtag ."#.as_bytes())
.collect::<Result<Vec<_>, _>>() .collect::<Result<Vec<_>, _>>()
.unwrap(); .unwrap();
assert_eq!( assert_eq!(

@ -22,12 +22,12 @@ use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::TriGParser; /// use oxttl::TriGParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -100,12 +100,12 @@ impl TriGParser {
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::TriGParser; /// use oxttl::TriGParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -133,12 +133,12 @@ impl TriGParser {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
@ -220,12 +220,12 @@ impl TriGParser {
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::TriGParser; /// use oxttl::TriGParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -253,10 +253,10 @@ impl<R: Read> FromReadTriGReader<R> {
/// ``` /// ```
/// use oxttl::TriGParser; /// use oxttl::TriGParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TriGParser::new().parse_read(file.as_ref()); /// let mut reader = TriGParser::new().parse_read(file.as_ref());
/// assert!(reader.prefixes().is_empty()); // No prefix at the beginning /// assert!(reader.prefixes().is_empty()); // No prefix at the beginning
@ -274,10 +274,10 @@ impl<R: Read> FromReadTriGReader<R> {
/// ``` /// ```
/// use oxttl::TriGParser; /// use oxttl::TriGParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TriGParser::new().parse_read(file.as_ref()); /// let mut reader = TriGParser::new().parse_read(file.as_ref());
/// assert!(reader.base_iri().is_none()); // No base at the beginning because none has been given to the parser. /// assert!(reader.base_iri().is_none()); // No base at the beginning because none has been given to the parser.
@ -314,12 +314,12 @@ impl<R: Read> Iterator for FromReadTriGReader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
@ -358,10 +358,10 @@ impl<R: AsyncRead + Unpin> FromTokioAsyncReadTriGReader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TriGParser::new().parse_tokio_async_read(file.as_ref()); /// let mut reader = TriGParser::new().parse_tokio_async_read(file.as_ref());
/// assert!(reader.prefixes().is_empty()); // No prefix at the beginning /// assert!(reader.prefixes().is_empty()); // No prefix at the beginning
@ -382,10 +382,10 @@ impl<R: AsyncRead + Unpin> FromTokioAsyncReadTriGReader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TriGParser::new().parse_tokio_async_read(file.as_ref()); /// let mut reader = TriGParser::new().parse_tokio_async_read(file.as_ref());
/// assert!(reader.base_iri().is_none()); // No base IRI at the beginning /// assert!(reader.base_iri().is_none()); // No base IRI at the beginning
@ -481,10 +481,10 @@ impl LowLevelTriGReader {
/// ``` /// ```
/// use oxttl::TriGParser; /// use oxttl::TriGParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TriGParser::new().parse(); /// let mut reader = TriGParser::new().parse();
/// reader.extend_from_slice(file); /// reader.extend_from_slice(file);
@ -503,10 +503,10 @@ impl LowLevelTriGReader {
/// ``` /// ```
/// use oxttl::TriGParser; /// use oxttl::TriGParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TriGParser::new().parse(); /// let mut reader = TriGParser::new().parse();
/// reader.extend_from_slice(file); /// reader.extend_from_slice(file);

@ -24,12 +24,12 @@ use tokio::io::{AsyncRead, AsyncWrite};
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::TurtleParser; /// use oxttl::TurtleParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -102,12 +102,12 @@ impl TurtleParser {
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::TurtleParser; /// use oxttl::TurtleParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -135,12 +135,12 @@ impl TurtleParser {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
@ -222,12 +222,12 @@ impl TurtleParser {
/// use oxrdf::{NamedNodeRef, vocab::rdf}; /// use oxrdf::{NamedNodeRef, vocab::rdf};
/// use oxttl::TurtleParser; /// use oxttl::TurtleParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
@ -255,10 +255,10 @@ impl<R: Read> FromReadTurtleReader<R> {
/// ``` /// ```
/// use oxttl::TurtleParser; /// use oxttl::TurtleParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TurtleParser::new().parse_read(file.as_ref()); /// let mut reader = TurtleParser::new().parse_read(file.as_ref());
/// assert!(reader.prefixes().is_empty()); // No prefix at the beginning /// assert!(reader.prefixes().is_empty()); // No prefix at the beginning
@ -276,10 +276,10 @@ impl<R: Read> FromReadTurtleReader<R> {
/// ``` /// ```
/// use oxttl::TurtleParser; /// use oxttl::TurtleParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TurtleParser::new().parse_read(file.as_ref()); /// let mut reader = TurtleParser::new().parse_read(file.as_ref());
/// assert!(reader.base_iri().is_none()); // No base at the beginning because none has been given to the parser. /// assert!(reader.base_iri().is_none()); // No base at the beginning because none has been given to the parser.
@ -316,12 +316,12 @@ impl<R: Read> Iterator for FromReadTurtleReader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" . /// schema:name "Foo" .
/// <bar> a schema:Person ; /// <bar> a schema:Person ;
/// schema:name \"Bar\" ."; /// schema:name "Bar" ."#;
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
@ -360,10 +360,10 @@ impl<R: AsyncRead + Unpin> FromTokioAsyncReadTurtleReader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TurtleParser::new().parse_tokio_async_read(file.as_ref()); /// let mut reader = TurtleParser::new().parse_tokio_async_read(file.as_ref());
/// assert!(reader.prefixes().is_empty()); // No prefix at the beginning /// assert!(reader.prefixes().is_empty()); // No prefix at the beginning
@ -384,10 +384,10 @@ impl<R: AsyncRead + Unpin> FromTokioAsyncReadTurtleReader<R> {
/// ///
/// # #[tokio::main(flavor = "current_thread")] /// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> Result<(), oxttl::ParseError> { /// # async fn main() -> Result<(), oxttl::ParseError> {
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TurtleParser::new().parse_tokio_async_read(file.as_ref()); /// let mut reader = TurtleParser::new().parse_tokio_async_read(file.as_ref());
/// assert!(reader.base_iri().is_none()); // No base IRI at the beginning /// assert!(reader.base_iri().is_none()); // No base IRI at the beginning
@ -483,10 +483,10 @@ impl LowLevelTurtleReader {
/// ``` /// ```
/// use oxttl::TurtleParser; /// use oxttl::TurtleParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TurtleParser::new().parse(); /// let mut reader = TurtleParser::new().parse();
/// reader.extend_from_slice(file); /// reader.extend_from_slice(file);
@ -505,10 +505,10 @@ impl LowLevelTurtleReader {
/// ``` /// ```
/// use oxttl::TurtleParser; /// use oxttl::TurtleParser;
/// ///
/// let file = b"@base <http://example.com/> . /// let file = br#"@base <http://example.com/> .
/// @prefix schema: <http://schema.org/> . /// @prefix schema: <http://schema.org/> .
/// <foo> a schema:Person ; /// <foo> a schema:Person ;
/// schema:name \"Foo\" ."; /// schema:name "Foo" ."#;
/// ///
/// let mut reader = TurtleParser::new().parse(); /// let mut reader = TurtleParser::new().parse();
/// reader.extend_from_slice(file); /// reader.extend_from_slice(file);

@ -22,11 +22,11 @@ use std::sync::Arc;
/// ///
/// let json_parser = QueryResultsParser::from_format(QueryResultsFormat::Json); /// let json_parser = QueryResultsParser::from_format(QueryResultsFormat::Json);
/// // boolean /// // boolean
/// if let FromReadQueryResultsReader::Boolean(v) = json_parser.parse_read(b"{\"boolean\":true}".as_slice())? { /// if let FromReadQueryResultsReader::Boolean(v) = json_parser.parse_read(br#"{"boolean":true}"#.as_slice())? {
/// assert_eq!(v, true); /// assert_eq!(v, true);
/// } /// }
/// // solutions /// // solutions
/// if let FromReadQueryResultsReader::Solutions(solutions) = json_parser.parse_read(b"{\"head\":{\"vars\":[\"foo\",\"bar\"]},\"results\":{\"bindings\":[{\"foo\":{\"type\":\"literal\",\"value\":\"test\"}}]}}".as_slice())? { /// if let FromReadQueryResultsReader::Solutions(solutions) = json_parser.parse_read(br#"{"head":{"vars":["foo","bar"]},"results":{"bindings":[{"foo":{"type":"literal","value":"test"}}]}}"#.as_slice())? {
/// assert_eq!(solutions.variables(), &[Variable::new_unchecked("foo"), Variable::new_unchecked("bar")]); /// assert_eq!(solutions.variables(), &[Variable::new_unchecked("foo"), Variable::new_unchecked("bar")]);
/// for solution in solutions { /// for solution in solutions {
/// assert_eq!(solution?.iter().collect::<Vec<_>>(), vec![(&Variable::new_unchecked("foo"), &Literal::from("test").into())]); /// assert_eq!(solution?.iter().collect::<Vec<_>>(), vec![(&Variable::new_unchecked("foo"), &Literal::from("test").into())]);
@ -57,12 +57,12 @@ impl QueryResultsParser {
/// let json_parser = QueryResultsParser::from_format(QueryResultsFormat::Xml); /// let json_parser = QueryResultsParser::from_format(QueryResultsFormat::Xml);
/// ///
/// // boolean /// // boolean
/// if let FromReadQueryResultsReader::Boolean(v) = json_parser.parse_read(b"<sparql xmlns=\"http://www.w3.org/2005/sparql-results#\"><head/><boolean>true</boolean></sparql>".as_slice())? { /// if let FromReadQueryResultsReader::Boolean(v) = json_parser.parse_read(br#"<sparql xmlns="http://www.w3.org/2005/sparql-results#"><head/><boolean>true</boolean></sparql>"#.as_slice())? {
/// assert_eq!(v, true); /// assert_eq!(v, true);
/// } /// }
/// ///
/// // solutions /// // solutions
/// if let FromReadQueryResultsReader::Solutions(solutions) = json_parser.parse_read(b"<sparql xmlns=\"http://www.w3.org/2005/sparql-results#\"><head><variable name=\"foo\"/><variable name=\"bar\"/></head><results><result><binding name=\"foo\"><literal>test</literal></binding></result></results></sparql>".as_slice())? { /// if let FromReadQueryResultsReader::Solutions(solutions) = json_parser.parse_read(br#"<sparql xmlns="http://www.w3.org/2005/sparql-results#"><head><variable name="foo"/><variable name="bar"/></head><results><result><binding name="foo"><literal>test</literal></binding></result></results></sparql>"#.as_slice())? {
/// assert_eq!(solutions.variables(), &[Variable::new_unchecked("foo"), Variable::new_unchecked("bar")]); /// assert_eq!(solutions.variables(), &[Variable::new_unchecked("foo"), Variable::new_unchecked("bar")]);
/// for solution in solutions { /// for solution in solutions {
/// assert_eq!(solution?.iter().collect::<Vec<_>>(), vec![(&Variable::new_unchecked("foo"), &Literal::from("test").into())]); /// assert_eq!(solution?.iter().collect::<Vec<_>>(), vec![(&Variable::new_unchecked("foo"), &Literal::from("test").into())]);
@ -164,7 +164,7 @@ pub enum FromReadQueryResultsReader<R: Read> {
/// use oxrdf::{Literal, Variable}; /// use oxrdf::{Literal, Variable};
/// ///
/// let json_parser = QueryResultsParser::from_format(QueryResultsFormat::Json); /// let json_parser = QueryResultsParser::from_format(QueryResultsFormat::Json);
/// if let FromReadQueryResultsReader::Solutions(solutions) = json_parser.parse_read(b"{\"head\":{\"vars\":[\"foo\",\"bar\"]},\"results\":{\"bindings\":[{\"foo\":{\"type\":\"literal\",\"value\":\"test\"}}]}}".as_slice())? { /// if let FromReadQueryResultsReader::Solutions(solutions) = json_parser.parse_read(br#"{"head":{"vars":["foo","bar"]},"results":{"bindings":[{"foo":{"type":"literal","value":"test"}}]}}"#.as_slice())? {
/// assert_eq!(solutions.variables(), &[Variable::new_unchecked("foo"), Variable::new_unchecked("bar")]); /// assert_eq!(solutions.variables(), &[Variable::new_unchecked("foo"), Variable::new_unchecked("bar")]);
/// for solution in solutions { /// for solution in solutions {
/// assert_eq!(solution?.iter().collect::<Vec<_>>(), vec![(&Variable::new_unchecked("foo"), &Literal::from("test").into())]); /// assert_eq!(solution?.iter().collect::<Vec<_>>(), vec![(&Variable::new_unchecked("foo"), &Literal::from("test").into())]);

@ -35,14 +35,14 @@ use tokio::io::AsyncWrite;
/// // boolean /// // boolean
/// let mut buffer = Vec::new(); /// let mut buffer = Vec::new();
/// json_serializer.serialize_boolean_to_write(&mut buffer, true)?; /// json_serializer.serialize_boolean_to_write(&mut buffer, true)?;
/// assert_eq!(buffer, b"{\"head\":{},\"boolean\":true}"); /// assert_eq!(buffer, br#"{"head":{},"boolean":true}"#);
/// ///
/// // solutions /// // solutions
/// let mut buffer = Vec::new(); /// let mut buffer = Vec::new();
/// let mut writer = json_serializer.serialize_solutions_to_write(&mut buffer, vec![Variable::new_unchecked("foo"), Variable::new_unchecked("bar")])?; /// let mut writer = json_serializer.serialize_solutions_to_write(&mut buffer, vec![Variable::new_unchecked("foo"), Variable::new_unchecked("bar")])?;
/// writer.write(once((VariableRef::new_unchecked("foo"), LiteralRef::from("test"))))?; /// writer.write(once((VariableRef::new_unchecked("foo"), LiteralRef::from("test"))))?;
/// writer.finish()?; /// writer.finish()?;
/// assert_eq!(buffer, b"{\"head\":{\"vars\":[\"foo\",\"bar\"]},\"results\":{\"bindings\":[{\"foo\":{\"type\":\"literal\",\"value\":\"test\"}}]}}"); /// assert_eq!(buffer, br#"{"head":{"vars":["foo","bar"]},"results":{"bindings":[{"foo":{"type":"literal","value":"test"}}]}}"#);
/// # std::io::Result::Ok(()) /// # std::io::Result::Ok(())
/// ``` /// ```
pub struct QueryResultsSerializer { pub struct QueryResultsSerializer {
@ -65,7 +65,7 @@ impl QueryResultsSerializer {
/// let xml_serializer = QueryResultsSerializer::from_format(QueryResultsFormat::Xml); /// let xml_serializer = QueryResultsSerializer::from_format(QueryResultsFormat::Xml);
/// let mut buffer = Vec::new(); /// let mut buffer = Vec::new();
/// xml_serializer.serialize_boolean_to_write(&mut buffer, true)?; /// xml_serializer.serialize_boolean_to_write(&mut buffer, true)?;
/// assert_eq!(buffer, b"<?xml version=\"1.0\"?><sparql xmlns=\"http://www.w3.org/2005/sparql-results#\"><head></head><boolean>true</boolean></sparql>"); /// assert_eq!(buffer, br#"<?xml version="1.0"?><sparql xmlns="http://www.w3.org/2005/sparql-results#"><head></head><boolean>true</boolean></sparql>"#);
/// # std::io::Result::Ok(()) /// # std::io::Result::Ok(())
/// ``` /// ```
pub fn serialize_boolean_to_write<W: Write>(&self, write: W, value: bool) -> io::Result<W> { pub fn serialize_boolean_to_write<W: Write>(&self, write: W, value: bool) -> io::Result<W> {
@ -89,7 +89,7 @@ impl QueryResultsSerializer {
/// let json_serializer = QueryResultsSerializer::from_format(QueryResultsFormat::Json); /// let json_serializer = QueryResultsSerializer::from_format(QueryResultsFormat::Json);
/// let mut buffer = Vec::new(); /// let mut buffer = Vec::new();
/// json_serializer.serialize_boolean_to_tokio_async_write(&mut buffer, false).await?; /// json_serializer.serialize_boolean_to_tokio_async_write(&mut buffer, false).await?;
/// assert_eq!(buffer, b"{\"head\":{},\"boolean\":false}"); /// assert_eq!(buffer, br#"{"head":{},"boolean":false}"r);
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
@ -134,7 +134,7 @@ impl QueryResultsSerializer {
/// let mut writer = xml_serializer.serialize_solutions_to_write(&mut buffer, vec![Variable::new_unchecked("foo"), Variable::new_unchecked("bar")])?; /// let mut writer = xml_serializer.serialize_solutions_to_write(&mut buffer, vec![Variable::new_unchecked("foo"), Variable::new_unchecked("bar")])?;
/// writer.write(once((VariableRef::new_unchecked("foo"), LiteralRef::from("test"))))?; /// writer.write(once((VariableRef::new_unchecked("foo"), LiteralRef::from("test"))))?;
/// writer.finish()?; /// writer.finish()?;
/// assert_eq!(buffer, b"<?xml version=\"1.0\"?><sparql xmlns=\"http://www.w3.org/2005/sparql-results#\"><head><variable name=\"foo\"/><variable name=\"bar\"/></head><results><result><binding name=\"foo\"><literal>test</literal></binding></result></results></sparql>"); /// assert_eq!(buffer, br#"<?xml version="1.0"?><sparql xmlns="http://www.w3.org/2005/sparql-results#"><head><variable name="foo"/><variable name="bar"/></head><results><result><binding name="foo"><literal>test</literal></binding></result></results></sparql>"#);
/// # std::io::Result::Ok(()) /// # std::io::Result::Ok(())
/// ``` /// ```
pub fn serialize_solutions_to_write<W: Write>( pub fn serialize_solutions_to_write<W: Write>(
@ -183,7 +183,7 @@ impl QueryResultsSerializer {
/// let mut writer = json_serializer.serialize_solutions_to_tokio_async_write(&mut buffer, vec![Variable::new_unchecked("foo"), Variable::new_unchecked("bar")]).await?; /// let mut writer = json_serializer.serialize_solutions_to_tokio_async_write(&mut buffer, vec![Variable::new_unchecked("foo"), Variable::new_unchecked("bar")]).await?;
/// writer.write(once((VariableRef::new_unchecked("foo"), LiteralRef::from("test")))).await?; /// writer.write(once((VariableRef::new_unchecked("foo"), LiteralRef::from("test")))).await?;
/// writer.finish().await?; /// writer.finish().await?;
/// assert_eq!(buffer, b"{\"head\":{\"vars\":[\"foo\",\"bar\"]},\"results\":{\"bindings\":[{\"foo\":{\"type\":\"literal\",\"value\":\"test\"}}]}}"); /// assert_eq!(buffer, br#"{"head":{"vars":["foo","bar"]},"results":{"bindings":[{"foo":{"type":"literal","value":"test"}}]}}"#);
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
@ -280,7 +280,7 @@ impl<W: Write> ToWriteSolutionsWriter<W> {
/// writer.write(once((VariableRef::new_unchecked("foo"), LiteralRef::from("test"))))?; /// writer.write(once((VariableRef::new_unchecked("foo"), LiteralRef::from("test"))))?;
/// writer.write(&QuerySolution::from((vec![Variable::new_unchecked("bar")], vec![Some(Literal::from("test").into())])))?; /// writer.write(&QuerySolution::from((vec![Variable::new_unchecked("bar")], vec![Some(Literal::from("test").into())])))?;
/// writer.finish()?; /// writer.finish()?;
/// assert_eq!(buffer, b"{\"head\":{\"vars\":[\"foo\",\"bar\"]},\"results\":{\"bindings\":[{\"foo\":{\"type\":\"literal\",\"value\":\"test\"}},{\"bar\":{\"type\":\"literal\",\"value\":\"test\"}}]}}"); /// assert_eq!(buffer, br#"{"head":{"vars":["foo","bar"]},"results":{"bindings":[{"foo":{"type":"literal","value":"test"}},{"bar":{"type":"literal","value":"test"}}]}}"#);
/// # std::io::Result::Ok(()) /// # std::io::Result::Ok(())
/// ``` /// ```
pub fn write<'a>( pub fn write<'a>(
@ -368,7 +368,7 @@ impl<W: AsyncWrite + Unpin> ToTokioAsyncWriteSolutionsWriter<W> {
/// writer.write(once((VariableRef::new_unchecked("foo"), LiteralRef::from("test")))).await?; /// writer.write(once((VariableRef::new_unchecked("foo"), LiteralRef::from("test")))).await?;
/// writer.write(&QuerySolution::from((vec![Variable::new_unchecked("bar")], vec![Some(Literal::from("test").into())]))).await?; /// writer.write(&QuerySolution::from((vec![Variable::new_unchecked("bar")], vec![Some(Literal::from("test").into())]))).await?;
/// writer.finish().await?; /// writer.finish().await?;
/// assert_eq!(buffer, b"{\"head\":{\"vars\":[\"foo\",\"bar\"]},\"results\":{\"bindings\":[{\"foo\":{\"type\":\"literal\",\"value\":\"test\"}},{\"bar\":{\"type\":\"literal\",\"value\":\"test\"}}]}}"); /// assert_eq!(buffer, br#"{"head":{"vars":["foo","bar"]},"results":{"bindings":[{"foo":{"type":"literal","value":"test"}},{"bar":{"type":"literal","value":"test"}}]}}"#);
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```

@ -43,7 +43,7 @@ impl QueryResults {
/// ///
/// let mut results = Vec::new(); /// let mut results = Vec::new();
/// store.query("SELECT ?s WHERE { ?s ?p ?o }")?.write(&mut results, QueryResultsFormat::Json)?; /// store.query("SELECT ?s WHERE { ?s ?p ?o }")?.write(&mut results, QueryResultsFormat::Json)?;
/// assert_eq!(results, "{\"head\":{\"vars\":[\"s\"]},\"results\":{\"bindings\":[{\"s\":{\"type\":\"uri\",\"value\":\"http://example.com\"}}]}}".as_bytes()); /// assert_eq!(results, r#"{"head":{"vars":["s"]},"results":{"bindings":[{"s":{"type":"uri","value":"http://example.com"}}]}}"#.as_bytes());
/// # Result::<_,Box<dyn std::error::Error>>::Ok(()) /// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ``` /// ```
pub fn write( pub fn write(

@ -30,13 +30,13 @@
//! //!
//! // Let's test with a boolean //! // Let's test with a boolean
//! assert_eq!( //! assert_eq!(
//! convert_json_to_tsv(b"{\"boolean\":true}".as_slice()).unwrap(), //! convert_json_to_tsv(br#"{"boolean":true}"#.as_slice()).unwrap(),
//! b"true" //! b"true"
//! ); //! );
//! //!
//! // And with a set of solutions //! // And with a set of solutions
//! assert_eq!( //! assert_eq!(
//! convert_json_to_tsv(b"{\"head\":{\"vars\":[\"foo\",\"bar\"]},\"results\":{\"bindings\":[{\"foo\":{\"type\":\"literal\",\"value\":\"test\"}}]}}".as_slice()).unwrap(), //! convert_json_to_tsv(br#"{"head":{"vars":["foo","bar"]},"results":{"bindings":[{"foo":{"type":"literal","value":"test"}}]}}"#.as_slice()).unwrap(),
//! b"?foo\t?bar\n\"test\"\t\n" //! b"?foo\t?bar\n\"test\"\t\n"
//! ); //! );
//! ``` //! ```

Loading…
Cancel
Save