### Example Usage: NTriples IRI Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/format.rs.html?search= Demonstrates how to get the canonical IRI for the NTriples format. ```rust use oxrdfio::RdfFormat; assert_eq!(RdfFormat::NTriples.iri(), "http://www.w3.org/ns/formats/N-Triples") ``` -------------------------------- ### Example Search Patterns Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/error.rs.html?search= Illustrates common search query patterns for exploring Rust standard library and type transformations. ```rust std::vec ``` ```rust u32 -> bool ``` ```rust Option, (T -> U) -> Option ``` -------------------------------- ### JsonLdProfileSet Usage Example Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.JsonLdProfileSet.html Demonstrates creating an empty JsonLdProfileSet, adding profiles using the BitOrAssign operator, and checking for the presence of a profile. ```rust use oxjsonld::{JsonLdProfile, JsonLdProfileSet}; let mut profile_set = JsonLdProfileSet::empty(); profile_set |= JsonLdProfile::Expanded; profile_set |= JsonLdProfile::Streaming; assert!(profile_set.contains(JsonLdProfile::Streaming)); assert_eq!( profile_set.into_iter().collect::>(), vec![JsonLdProfile::Expanded, JsonLdProfile::Streaming] ); ``` -------------------------------- ### Example: Parsing Turtle with Base IRI and Prefixes Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html?search= Demonstrates parsing Turtle data, checking for the base IRI before and after reading triples, and verifying prefixes. ```rust use oxrdfio::{RdfFormat, RdfParser}; let file = r"@base . @prefix schema: . a schema:Person ; schema:name \"Foo\"."; let mut parser = RdfParser::from_format(RdfFormat::Turtle).for_slice(file); assert!(parser.base_iri().is_none()); // No base at the beginning because none has been given to the parser. parser.next().unwrap()?; // We read the first triple assert_eq!(parser.base_iri(), Some("http://example.com/")); // There is now a base IRI. # Result::<_, Box>::Ok(()) ``` -------------------------------- ### Initialize RdfParser from Format Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.RdfParser.html?search=u32+-%3E+bool Creates a new RdfParser instance for a specified RDF format. This is the starting point for parsing RDF data. ```rust use oxrdfio::{RdfFormat, RdfParser}; let file = " ."; let quads = RdfParser::from_format(RdfFormat::NTriples) .for_reader(file.as_bytes()) .collect::, _>>()?; assert_eq!(quads.len(), 1); assert_eq!(quads[0].subject.to_string(), ""); ``` -------------------------------- ### RdfParser Usage Example Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html?search=std%3A%3Avec Demonstrates how to use the RdfParser to read and parse RDF data from a byte stream in NTriples format. ```APIDOC ## RdfParser Usage Example ### Description This example shows a common use case for `RdfParser`: parsing a string containing RDF data in NTriples format into a collection of quads. ### Method `RdfParser::from_format(RdfFormat::NTriples).for_reader(file.as_bytes()).collect::, _>>()` ### Parameters None directly in this example, but the parser is configured with `RdfFormat::NTriples`. ### Request Example ```rust use oxrdfio::{RdfFormat, RdfParser}; let file = " ."; let quads = RdfParser::from_format(RdfFormat::NTriples) .for_reader(file.as_bytes()) .collect::, _>>()?; assert_eq!(quads.len(), 1); assert_eq!(quads[0].subject.to_string(), ""); # std::io::Result::Ok(()) ``` ### Response #### Success Response - `Vec` - A vector of `Quad` objects representing the parsed RDF data. #### Response Example ```rust // The parsed quads would be available here // assert_eq!(quads[0].subject.to_string(), ""); ``` ``` -------------------------------- ### TokioAsyncWriterQuadSerializer Usage Example Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.TokioAsyncWriterQuadSerializer.html?search=u32+-%3E+bool This example demonstrates how to use TokioAsyncWriterQuadSerializer to serialize a quad to N-Quads format using an in-memory Vec as the async writer. It shows the initialization, serialization of a quad, and finishing the writing process. ```APIDOC ## TokioAsyncWriterQuadSerializer Example ### Description This example demonstrates how to use `TokioAsyncWriterQuadSerializer` to serialize a quad to N-Quads format using an in-memory `Vec` as the async writer. It shows the initialization, serialization of a quad, and finishing the writing process. ### Usage ```rust use oxrdfio::{RdfFormat, RdfSerializer}; use oxrdf::{Quad, NamedNode}; // Assuming this code is within an async function or block let mut serializer = RdfSerializer::from_format(RdfFormat::NQuads).for_tokio_async_writer(Vec::new()); serializer.serialize_quad(&Quad { subject: NamedNode::new("http://example.com/s")?.into(), predicate: NamedNode::new("http://example.com/p")?, object: NamedNode::new("http://example.com/o")?.into(), graph_name: NamedNode::new("http://example.com/g")?.into() }).await?; assert_eq!(serializer.finish().await?, b" .\n"); ``` ### Methods #### `serialize_quad` Serializes a `QuadRef`. #### `serialize_triple` Serializes a `TripleRef`. #### `finish` Writes the last bytes of the file. Note that this function does not flush the writer. You need to do that if you are using a `BufWriter`. ``` -------------------------------- ### JsonLdProfileSet::empty Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.JsonLdProfileSet.html Creates an empty JsonLdProfileSet. This is the starting point for building a set of profiles. ```APIDOC ## JsonLdProfileSet::empty ### Description Creates an empty `JsonLdProfileSet`. ### Method `const fn empty() -> JsonLdProfileSet` ### Example ```rust use oxjsonld::JsonLdProfileSet; let profile_set = JsonLdProfileSet::empty(); ``` ``` -------------------------------- ### Serializing a Quad with WriterQuadSerializer Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.WriterQuadSerializer.html Demonstrates how to serialize a single quad using `RdfSerializer::for_writer` and `serialize_quad`. Ensure to call `finish` to get the final output. ```rust use oxrdfio::{RdfFormat, RdfSerializer}; use oxrdf::{Quad, NamedNode}; let mut serializer = RdfSerializer::from_format(RdfFormat::NQuads).for_writer(Vec::new()); serializer.serialize_quad(&Quad { subject: NamedNode::new("http://example.com/s")?.into(), predicate: NamedNode::new("http://example.com/p")?, object: NamedNode::new("http://example.com/o")?.into(), graph_name: NamedNode::new("http://example.com/g")?.into(), })?; assert_eq!(serializer.finish()?, b" .\n"); ``` -------------------------------- ### Serializing a Triple with Prefixes in Turtle Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/serializer.rs.html Demonstrates how to create an RdfSerializer for Turtle format, set a prefix, and serialize a triple. Ensure to call `finish()` to get the complete output. ```rust use oxrdfio::{RdfFormat, RdfSerializer}; let mut serializer = RdfSerializer::from_format(RdfFormat::Turtle) .with_prefix("schema", "http://schema.org/")? .for_writer(Vec::new()); serializer.serialize_triple(TripleRef { subject: NamedNodeRef::new("http://example.com/s")?.into(), predicate: rdf::TYPE.into(), object: NamedNodeRef::new("http://schema.org/Person")?.into() })?; assert_eq!( serializer.finish()?, b"@prefix schema: .\n a schema:Person .\n" ); # Result::<_, Box>::Ok(()) ``` -------------------------------- ### RdfParser Usage Example Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create an RdfParser for a specific format (NTriples in this case), read data from a byte slice, and collect the parsed quads. It also shows basic assertion for the parsed data. ```APIDOC ## RdfParser Usage Example ### Description This example shows how to use the `RdfParser` to parse RDF data from a byte slice in NTriples format. It demonstrates creating a parser, reading data, and collecting the resulting quads, with a basic assertion to verify the parsed content. ### Method `RdfParser::from_format(RdfFormat::NTriples).for_reader(file.as_bytes()).collect::, _>>()` ### Endpoint N/A (This is a library usage example, not an HTTP endpoint) ### Parameters - `format`: The RDF format to use for parsing (e.g., `RdfFormat::NTriples`). - `reader`: A source of bytes to read from (e.g., `file.as_bytes()`). ### Request Example ```rust use oxrdfio::{RdfFormat, RdfParser}; let file = " ."; let quads = RdfParser::from_format(RdfFormat::NTriples) .for_reader(file.as_bytes()) .collect::, _>>()?; assert_eq!(quads.len(), 1); assert_eq!(quads[0].subject.to_string(), ""); ``` ### Response #### Success Response - `Vec`: A vector of parsed RDF quads. #### Response Example ```json [ { "subject": {"value": "http://example.com/s", "type": "iri"}, "predicate": {"value": "http://example.com/p", "type": "iri"}, "object": {"value": "http://example.com/o", "type": "iri"}, "graph_name": null } ] ``` ``` -------------------------------- ### JsonLdProfileSet::empty Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.JsonLdProfileSet.html?search=u32+-%3E+bool Creates an empty JsonLdProfileSet. This is the starting point for building a set of JSON-LD profiles. ```APIDOC ## JsonLdProfileSet::empty ### Description Creates an empty set of JSON-Ld profiles. ### Method `const fn empty() -> JsonLdProfileSet` ### Returns A new, empty `JsonLdProfileSet`. ``` -------------------------------- ### RdfSerializer::from_format and serialize_quad Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/serializer.rs.html Initializes an RdfSerializer for a given format and writes a quad to the output. This example demonstrates serializing a single quad into N-Quads format. ```APIDOC ## RdfSerializer::from_format and serialize_quad ### Description Initializes an RdfSerializer for a given format and writes a quad to the output. This example demonstrates serializing a single quad into N-Quads format. ### Method ```rust pub fn from_format(format: RdfFormat) -> Self ``` ### Endpoint N/A (SDK method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```rust use oxrdfio::{RdfFormat, RdfSerializer}; use oxrdf::{Quad, NamedNode}; let mut serializer = RdfSerializer::from_format(RdfFormat::NQuads).for_writer(Vec::new()); serializer.serialize_quad(&Quad { subject: NamedNode::new("http://example.com/s")?.into(), predicate: NamedNode::new("http://example.com/p")?, object: NamedNode::new("http://example.com/o")?.into(), graph_name: NamedNode::new("http://example.com/g")?.into() })?; assert_eq!(serializer.finish()?, b" .\n"); # Result::<_, Box>::Ok(()) ``` ### Response #### Success Response (200) N/A (SDK method returns Result) #### Response Example N/A ``` -------------------------------- ### Serialize RDF data with Tokio Async Writer Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/serializer.rs.html?search=u32+-%3E+bool Example demonstrating how to serialize a quad using `RdfSerializer` with Tokio's async writer. Remember to call `finish()` to write the last bytes and consider using `BufWriter` for better performance. ```rust use oxrdfio::{RdfFormat, RdfSerializer}; use oxrdf::{Quad, NamedNode}; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Box> { let mut serializer = RdfSerializer::from_format(RdfFormat::NQuads).for_tokio_async_writer(Vec::new()); serializer.serialize_quad(&Quad { subject: NamedNode::new("http://example.com/s")?.into(), predicate: NamedNode::new("http://example.com/p")?, object: NamedNode::new("http://example.com/o")?.into(), graph_name: NamedNode::new("http://example.com/g")?.into() }).await?; assert_eq!(serializer.finish().await?, b" .\n"); Ok(()) } ``` -------------------------------- ### Parsing Turtle with TokioAsyncReaderQuadParser and Checking Prefixes Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.TokioAsyncReaderQuadParser.html?search=u32+-%3E+bool Shows how to parse an RDF file in Turtle format and inspect prefixes during parsing. It demonstrates that the prefixes iterator is initially empty and gets populated after reading triples. ```rust use oxrdfio::{RdfFormat, RdfParser}; let file = r"@base . @prefix schema: . 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::>(), []); // No prefix at the beginning parser.next().await.unwrap()?; // We read the first triple assert_eq!( parser.prefixes().collect::>(), [("schema", "http://schema.org/")] ); // There are now prefixes // ``` -------------------------------- ### Retrieve Prefixes During Turtle Parsing Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html Demonstrates how to get prefixes from a Turtle RDF file during parsing. Prefixes are initially empty and populated as the parser encounters them. ```rust #[tokio::main(flavor = "current_thread")] # async fn main() -> Result<(), oxrdfio::RdfParseError> { use oxrdfio::{RdfFormat, RdfParser}; let file = r"@base . @prefix schema: . 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::>(), []); // No prefix at the beginning parser.next().await.unwrap()?; // We read the first triple assert_eq!( parser.prefixes().collect::>(), [("schema", "http://schema.org/")] ); // There are now prefixes // # Ok(()) # } ``` -------------------------------- ### Convert Turtle to N-Triples Source: https://docs.rs/oxrdfio/latest/index.html Example of converting a Turtle RDF file to an N-Triples RDF file using RdfParser and RdfSerializer. Requires importing RdfFormat, RdfParser, and RdfSerializer. ```rust use oxrdfio::{RdfFormat, RdfParser, RdfSerializer}; let turtle_file = b"@base .\n@prefix schema: .\n a schema:Person ;\n schema:name \"Foo\".\n a schema:Person ;\n schema:name \"Bar\"."; let ntriples_file = b" .\n \"Foo\".\n .\n \"Bar\".\n"; let mut serializer = RdfSerializer::from_format(RdfFormat::NTriples).for_writer(Vec::new()); for quad in RdfParser::from_format(RdfFormat::Turtle).for_reader(turtle_file.as_ref()) { serializer.serialize_quad(&quad.unwrap()).unwrap(); } assert_eq!(serializer.finish().unwrap(), ntriples_file); ``` -------------------------------- ### Convert Turtle to N-Triples Source: https://docs.rs/oxrdfio/latest/oxrdfio/index.html Example of converting a Turtle formatted string to N-Triples format using RdfParser and RdfSerializer. This snippet demonstrates reading from a byte slice and writing to a vector. ```rust use oxrdfio::{RdfFormat, RdfParser, RdfSerializer}; let turtle_file = b"@base . @prefix schema: . a schema:Person ; schema:name \"Foo\". a schema:Person ; schema:name \"Bar\"."; let ntriples_file = b" . \"Foo\". . \"Bar\". "; let mut serializer = RdfSerializer::from_format(RdfFormat::NTriples).for_writer(Vec::new()); for quad in RdfParser::from_format(RdfFormat::Turtle).for_reader(turtle_file.as_ref()) { serializer.serialize_quad(&quad.unwrap()).unwrap(); } assert_eq!(serializer.finish().unwrap(), ntriples_file); ``` -------------------------------- ### Checking Prefixes at the Start of Turtle Parsing Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html?search= Shows how to retrieve the list of declared prefixes during the parsing of a Turtle document. Initially, no prefixes are known, and this iterator will be empty. ```Rust use oxrdfio::{RdfFormat, RdfParser}; let file = r#"@base . @prefix schema: . a schema:Person ; schema:name "Foo" ."#; let mut parser = RdfParser::from_format(RdfFormat::Turtle).for_slice(file); assert!(parser.prefixes().collect::>().is_empty()); // No prefix at the beginning ``` -------------------------------- ### Get Prefixes from RDF Parser Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Iterates over the prefixes defined in the RDF document. This is useful for understanding the namespace mappings used in the data. Supported formats include JSON-LD, N3, TriG, Turtle, and RDF/XML. ```rust /// 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 . /// @prefix schema: . /// a schema:Person ; /// schema:name \"Foo\"."; /// /// let mut parser = RdfParser::from_format(RdfFormat::Turtle).for_slice(file); /// assert!(parser.base_iri().is_none()); // No base at the beginning because none has been given to the parser. /// /// parser.next().unwrap()?; /// assert_eq!(parser.base_iri(), Some("http://example.com/")); // There is now a base IRI. /// # Result::<_, Box>::Ok(()) /// ``` pub fn base_iri(&self) -> Option<&str> { match &self.inner { SliceQuadParserKind::JsonLd(p) => p.base_iri(), SliceQuadParserKind::N3(p) => p.base_iri(), SliceQuadParserKind::TriG(p) => p.base_iri(), SliceQuadParserKind::Turtle(p) => p.base_iri(), SliceQuadParserKind::RdfXml(p) => p.base_iri(), SliceQuadParserKind::NQuads(_) | SliceQuadParserKind::NTriples(_) => None, } } ``` -------------------------------- ### Retrieving Base IRI during RDF Parsing Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html?search= Shows how to get the base IRI during RDF parsing. It starts as None and is populated once a base IRI is encountered in the input, specifically for formats like Turtle. ```Rust use oxrdfio::{RdfFormat, RdfParser}; let file = r"@base . @prefix schema: . a schema:Person ; schema:name \"Foo\"."; let mut parser = RdfParser::from_format(RdfFormat::Turtle).for_reader(file.as_bytes()); assert!(parser.base_iri().is_none()); // No base at the beginning because none has been given to the parser. parser.next().unwrap()?; // We read the first triple assert_eq!(parser.base_iri(), Some("http://example.com/")); // There is now a base IRI. // # Result::<_, Box>::Ok(()) ``` -------------------------------- ### prefixes Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html Retrieves an iterator over the IRI prefixes encountered during parsing. The prefixes are returned as (prefix name, prefix value) tuples. This iterator is empty at the start of parsing and gets updated as prefixes are found. If a format does not support prefixes, an empty iterator is returned. If a prefix is overridden, only the latest version is provided. ```APIDOC ## prefixes ### Description Returns an iterator over the IRI prefixes encountered during parsing. Prefixes are returned as (prefix name, prefix value) tuples. The iterator is empty at the start and updated as prefixes are found. If a format does not support prefixes, an empty iterator is returned. Overridden prefixes will only return the latest version. ### Method `prefixes()` ### Parameters None ### Returns `PrefixesIter<'_>` - An iterator over the IRI prefixes. ### Example ```rust use oxrdfio::{RdfFormat, RdfParser}; let file = r"@base . @prefix schema: . a schema:Person ; schema:name \"Foo\"."; let mut parser = RdfParser::from_format(RdfFormat::Turtle).for_reader(file.as_bytes()); assert!(parser.prefixes().collect::>().is_empty()); // No prefix at the beginning parser.next().unwrap()?; assert_eq!( parser.prefixes().collect::>(), [("schema", "http://schema.org/")] ); // There are now prefixes ``` ``` -------------------------------- ### Get Serializer Format Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.RdfSerializer.html Retrieves the RDF format that the RdfSerializer is configured to use. ```rust use oxrdfio::{RdfFormat, RdfSerializer}; assert_eq!( RdfSerializer::from_format(RdfFormat::Turtle).format(), RdfFormat::Turtle ); ``` -------------------------------- ### Any::type_id implementation Source: https://docs.rs/oxrdfio/latest/oxrdfio/enum.RdfParseError.html Gets the TypeId of a value, used for dynamic type checking. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Get File Extension for RdfFormat Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/format.rs.html?search= Provides the IANA-registered file extension for each RdfFormat variant. ```rust pub const fn file_extension(self) -> &'static str { match self { Self::JsonLd { .. } => "jsonld", Self::N3 => "n3", Self::NQuads => "nq", Self::NTriples => "nt", Self::RdfXml => "rdf", Self::TriG => "trig", Self::Turtle => "ttl", } } ``` -------------------------------- ### Get Name for RdfFormat Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/format.rs.html?search= Returns the human-readable name of the RdfFormat. Differentiates between standard and streaming JSON-LD. ```rust pub const fn name(self) -> &'static str { match self { Self::JsonLd { profile } => { // TODO: more combinations if profile.contains(JsonLdProfile::Streaming) { "Streaming JSON-LD" } else { "JSON-LD" } } Self::N3 => "N3", Self::NQuads => "N-Quads", Self::NTriples => "N-Triples", Self::RdfXml => "RDF/XML", Self::TriG => "TriG", Self::Turtle => "Turtle", } } ``` -------------------------------- ### JsonLdProfileSet Constructors Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.JsonLdProfileSet.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides methods to create new instances of JsonLdProfileSet. `empty()` creates an empty set, while `from_profile()` creates a set with a single specified profile. ```APIDOC ## `empty()` ### Description Creates an empty `JsonLdProfileSet`. ### Returns A new, empty `JsonLdProfileSet`. ## `from_profile(profile: JsonLdProfile)` ### Description Creates a `JsonLdProfileSet` containing a single specified profile. ### Parameters * `profile` (JsonLdProfile) - The profile to include in the set. ### Returns A new `JsonLdProfileSet` containing the given profile. ``` -------------------------------- ### Get RdfFormat Name Source: https://docs.rs/oxrdfio/latest/oxrdfio/enum.RdfFormat.html Retrieves the human-readable name for an RdfFormat variant. This is useful for display purposes. ```rust use oxrdfio::RdfFormat; assert_eq!(RdfFormat::NTriples.name(), "N-Triples") ``` -------------------------------- ### Serializing a Triple with Prefixes in Turtle Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/serializer.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create an RdfSerializer for Turtle format, set a prefix, serialize a triple, and finish the serialization. Ensure to handle potential errors from prefix and IRI parsing. ```rust let mut serializer = RdfSerializer::from_format(RdfFormat::Turtle) .with_prefix("schema", "http://schema.org/")? .for_writer(Vec::new()); serializer.serialize_triple(TripleRef { subject: NamedNodeRef::new("http://example.com/s")?.into(), predicate: rdf::TYPE.into(), object: NamedNodeRef::new("http://schema.org/Person")?.into(), })?; assert_eq!( serializer.finish()?, b"@prefix schema: .\n a schema:Person .\n" ); # Result::<_, Box>::Ok(()) ``` -------------------------------- ### SliceQuadParser Iterator step_by() Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.SliceQuadParser.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates an iterator starting at the same point, but stepping by the given amount at each iteration. ```APIDOC ## fn step_by(self, step: usize) -> StepBy where Self: Sized, Creates an iterator starting at the same point, but stepping by the given amount at each iteration. Read more ``` -------------------------------- ### RdfParser::from_format Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.RdfParser.html?search=u32+-%3E+bool Builds a new RdfParser instance for a specified RDF format. This is the entry point for creating a parser. ```APIDOC ## RdfParser::from_format ### Description Builds a parser for the given format. ### Method `pub fn from_format(format: RdfFormat) -> Self` ### Parameters * `format` (RdfFormat) - The RDF format to use for parsing. ``` -------------------------------- ### RdfParser::from_format Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.RdfParser.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Builds a new RdfParser instance for a specified RDF format. This is the entry point for creating a parser. ```APIDOC ## RdfParser::from_format ### Description Builds a parser for the given format. ### Method `from_format(format: RdfFormat) -> Self` ### Parameters * **format** (RdfFormat) - The RDF format to use for parsing. ``` -------------------------------- ### Get RdfParser Format Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.RdfParser.html?search=u32+-%3E+bool Retrieves the RDF format that the RdfParser is configured to use. Useful for verifying parser settings. ```rust use oxrdfio::{RdfFormat, RdfParser}; assert_eq!( RdfParser::from_format(RdfFormat::Turtle).format(), RdfFormat::Turtle ); ``` -------------------------------- ### Serialize RDF Quads to Tokio Async Writer Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.RdfSerializer.html Demonstrates serializing RDF quads asynchronously using Tokio's `AsyncWrite`. Ensure to call `finish().await` to complete the serialization. ```rust use oxrdfio::{RdfFormat, RdfSerializer}; use oxrdf::{Quad, NamedNode}; let mut serializer = RdfSerializer::from_format(RdfFormat::NQuads).for_tokio_async_writer(Vec::new()); serializer.serialize_quad(&Quad { subject: NamedNode::new("http://example.com/s")?.into(), predicate: NamedNode::new("http://example.com/p")?, object: NamedNode::new("http://example.com/o")?.into(), graph_name: NamedNode::new("http://example.com/g")?.into() }).await?; assert_eq!(serializer.finish().await?, b" .\n"); ``` -------------------------------- ### Get Error Location Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.RdfSyntaxError.html?search= Retrieves the specific location (range of text positions) within the file where the RdfSyntaxError occurred. ```rust pub fn location(&self) -> Option> ``` -------------------------------- ### TryFrom and TryInto Implementations Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.SliceQuadParser.html Documentation for the TryFrom and TryInto trait implementations, which allow for fallible type conversions. ```APIDOC ### impl TryFrom for T #### type Error = Infallible #### fn try_from(value: U) -> Result>::Error> ### impl TryInto for T #### type Error = >::Error #### fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Error::cause for RdfParseError (Deprecated) Source: https://docs.rs/oxrdfio/latest/oxrdfio/enum.RdfParseError.html Deprecated method to get the cause of the error. Use Error::source instead. ```rust fn cause(&self) -> Option<&dyn Error> ``` -------------------------------- ### Setting Base IRI and Prefixes for Turtle Serialization Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/serializer.rs.html Shows how to configure an RdfSerializer for Turtle format with both a base IRI and custom prefixes before serializing a triple. Remember to call `finish()` for the complete output. ```rust use oxrdf::vocab::rdf; use oxrdf::{NamedNodeRef, TripleRef}; use oxrdfio::{RdfFormat, RdfSerializer}; let mut serializer = RdfSerializer::from_format(RdfFormat::Turtle) .with_base_iri("http://example.com")? .with_prefix("ex", "http://example.com/ns#")? .for_writer(Vec::new()); serializer.serialize_triple(TripleRef::new( NamedNodeRef::new("http://example.com/me")?, rdf::TYPE, NamedNodeRef::new("http://example.com/ns#Person")?, ))?; assert_eq!( serializer.finish()?, b"@base .\n@prefix ex: .\n a ex:Person .\n", ); # Result::<_,Box>::Ok(()) ``` -------------------------------- ### Error::description for RdfParseError (Deprecated) Source: https://docs.rs/oxrdfio/latest/oxrdfio/enum.RdfParseError.html Deprecated method to get a description of the error. Use Display or to_string() instead. ```rust fn description(&self) -> &str ``` -------------------------------- ### RdfParser::from_format Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.RdfParser.html?search= Builds a parser for a given RDF format. This is the entry point for creating an RdfParser instance. ```APIDOC ## RdfParser::from_format ### Description Builds a parser for the given format. This is the primary method to instantiate an `RdfParser`. ### Method `pub fn from_format(format: RdfFormat) -> Self` ### Parameters * **format** (`RdfFormat`) - The RDF serialization format to use for parsing. ``` -------------------------------- ### Setting Base IRI and Prefixes for Turtle Serialization Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/serializer.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows how to configure an RdfSerializer for Turtle format with both a base IRI and a custom prefix, then serialize a triple. The output reflects the applied base IRI and prefix. ```rust let mut serializer = RdfSerializer::from_format(RdfFormat::Turtle) .with_base_iri("http://example.com")? .with_prefix("ex", "http://example.com/ns#")? .for_writer(Vec::new()); serializer.serialize_triple(TripleRef::new( NamedNodeRef::new("http://example.com/me")?, rdf::TYPE, NamedNodeRef::new("http://example.com/ns#Person")?, ))?; assert_eq!( serializer.finish()?, b"@base .\n@prefix ex: .\n a ex:Person .\n", ); # Result::<_,Box>::Ok(()) ``` -------------------------------- ### Parallel Parsing of RDF Files Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html?search= Demonstrates how to parse an RDF file in parallel by splitting it into chunks. This is useful for large files to leverage multiple CPU cores. Requires a file path and the desired level of parallelism. ```Rust /// # let path = tempfile::NamedTempFile::new()?; /// # std::fs::write(&path, " .")?; /// /// let quads = RdfParser::from_format(RdfFormat::NTriples) /// .split_file_for_parallel_parsing(&path, 4)? /// .into_iter() /// .flatten() /// .collect::, _>>()?; /// /// assert_eq!(quads.len(), 1); /// assert_eq!(quads[0].subject.to_string(), ""); /// # std::io::Result::Ok(()) /// ``` ``` -------------------------------- ### Get Media Type for RdfFormat Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/format.rs.html?search= Returns the IANA media type for an RdfFormat. Handles specific cases for JSON-LD with streaming profiles. ```rust pub const fn media_type(self) -> &'static str { match self { Self::JsonLd { profile } => { // TODO: more combinations if profile.contains(JsonLdProfile::Streaming) { "application/ld+json;profile=http://www.w3.org/ns/json-ld#streaming" } else { "application/ld+json" } } Self::N3 => "text/n3", Self::NQuads => "application/n-quads", Self::NTriples => "application/n-triples", Self::RdfXml => "application/rdf+xml", Self::TriG => "application/trig", Self::Turtle => "text/turtle", } } ``` -------------------------------- ### Get Canonical IRI for RdfFormat Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/format.rs.html?search= Retrieves the canonical IRI for an RdfFormat variant, as defined by the Unique URIs for file formats registry. ```rust pub const fn iri(self) -> &'static str { match self { Self::JsonLd { .. } => "https://www.w3.org/ns/formats/data/JSON-LD", Self::N3 => "http://www.w3.org/ns/formats/N3", Self::NQuads => "http://www.w3.org/ns/formats/N-Quads", Self::NTriples => "http://www.w3.org/ns/formats/N-Triples", Self::RdfXml => "http://www.w3.org/ns/formats/RDF_XML", Self::TriG => "http://www.w3.org/ns/formats/TriG", Self::Turtle => "http://www.w3.org/ns/formats/Turtle", } } ``` -------------------------------- ### Error::provide Implementation (Nightly) Source: https://docs.rs/oxrdfio/latest/oxrdfio/enum.RdfParseError.html?search= Nightly-only experimental API for providing type-based access to error context. ```rust fn provide<'a>(&'a self, request: &mut Request<'a>) { // ... implementation details ... } ``` -------------------------------- ### Get Canonical IRI for JsonLdProfile::Expanded Source: https://docs.rs/oxrdfio/latest/oxrdfio/enum.JsonLdProfile.html Demonstrates how to retrieve the canonical IRI for the Expanded JSON-LD profile. This is useful for interoperability and validation. ```rust use oxjsonld::JsonLdProfile; assert_eq!( JsonLdProfile::Expanded.iri(), "http://www.w3.org/ns/json-ld#expanded" ) ``` -------------------------------- ### Get RdfFormat File Extension Source: https://docs.rs/oxrdfio/latest/oxrdfio/enum.RdfFormat.html Retrieves the IANA-registered file extension for an RdfFormat variant. This is useful for determining file types based on their extension. ```rust use oxrdfio::RdfFormat; assert_eq!(RdfFormat::NTriples.file_extension(), "nt") ``` -------------------------------- ### Parsing Turtle with TokioAsyncReaderQuadParser and Checking Base IRI Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.TokioAsyncReaderQuadParser.html?search=u32+-%3E+bool Illustrates parsing an RDF file in Turtle format and checking the base IRI. It shows that the base IRI is initially None and becomes available after reading the first triple. ```rust use oxrdfio::{RdfFormat, RdfParser}; let file = r"@base . @prefix schema: . 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 // ``` -------------------------------- ### Parallel Parsing of RDF Files Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to parse an RDF file in parallel using N-Triples format. This is useful for large files where performance is critical. Requires a file path and the desired level of parallelism. ```Rust use oxrdfio::{RdfFormat, RdfParser}; use std::io::Write; // Create a temporary file with N-Triples data let mut path = tempfile::NamedTempFile::new()?; writeln!(&path, " .")?; // Parse the file in parallel, splitting it into 4 chunks let quads = RdfParser::from_format(RdfFormat::NTriples) .split_file_for_parallel_parsing(&path, 4)? .into_iter() .flatten() .collect::, _>>()?; assert_eq!(quads.len(), 1); assert_eq!(quads[0].subject.to_string(), ""); std::io::Result::Ok(()) ``` -------------------------------- ### RdfSerializer::with_prefix Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.RdfSerializer.html Sets a prefix for the serializer if the format supports it. ```APIDOC ## RdfSerializer::with_prefix ### Description If the format supports it, sets a prefix. ### Method `RdfSerializer::with_prefix(self, prefix_name: impl Into, prefix_iri: impl Into) -> Result` ### Parameters * `prefix_name` (impl Into) - The name of the prefix. * `prefix_iri` (impl Into) - The IRI associated with the prefix. ### Returns `Result` - The serializer instance with the prefix set, or an error if the IRI is invalid. ``` -------------------------------- ### Get Prefixes from RDF Parser Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html Iterates over all declared prefixes in the RDF document. Useful for understanding namespace mappings. Prefixes are available after parsing has begun. ```rust /// assert!(parser.prefixes().collect::>().is_empty()); // No prefix at the beginning /// /// parser.next().unwrap()?; // We read the first triple /// assert_eq!( /// parser.prefixes().collect::>(), /// [("schema", "http://schema.org/")] /// ); // There are now prefixes /// // /// # Result::<_, Box>::Ok(()) /// /// ``` /// pub fn prefixes(&self) -> PrefixesIter<'_> { /// PrefixesIter { /// inner: match &self.inner { /// SliceQuadParserKind::JsonLd(p) => PrefixesIterKind::JsonLd(p.prefixes()), /// SliceQuadParserKind::N3(p) => PrefixesIterKind::N3(p.prefixes()), /// SliceQuadParserKind::TriG(p) => PrefixesIterKind::TriG(p.prefixes()), /// SliceQuadParserKind::Turtle(p) => PrefixesIterKind::Turtle(p.prefixes()), /// SliceQuadParserKind::RdfXml(p) => PrefixesIterKind::RdfXml(p.prefixes()), /// SliceQuadParserKind::NQuads(_) | SliceQuadParserKind::NTriples(_) => { /// PrefixesIterKind::None /// } /// }, /// } /// } ``` -------------------------------- ### Serialize a Quad to N-Quads Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/serializer.rs.html Demonstrates how to create an RdfSerializer for N-Quads format, write a single quad, and finish the serialization. This is useful for writing RDF data to a byte vector. ```rust use oxrdfio::{RdfFormat, RdfSerializer}; use oxrdf::{Quad, NamedNode}; let mut serializer = RdfSerializer::from_format(RdfFormat::NQuads).for_writer(Vec::new()); serializer.serialize_quad(&Quad { subject: NamedNode::new("http://example.com/s")?.into(), predicate: NamedNode::new("http://example.com/p")?, object: NamedNode::new("http://example.com/o")?.into(), graph_name: NamedNode::new("http://example.com/g")?.into() })?; assert_eq!(serializer.finish()?, b" .\n"); # Result::<_, Box>::Ok(()) ``` -------------------------------- ### Accessing Base IRI in Turtle Parsing Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.ReaderQuadParser.html?search=u32+-%3E+bool Demonstrates how to get the base IRI during Turtle parsing. It is initially None and set once a base IRI is encountered. ```Rust use oxrdfio::{RdfFormat, RdfParser}; let file = r"@base . @prefix schema: . a schema:Person ; schema:name \"Foo\"."; let mut parser = RdfParser::from_format(RdfFormat::Turtle).for_reader(file.as_bytes()); assert!(parser.base_iri().is_none()); // No base at the beginning because none has been given to the parser. parser.next().unwrap()?; // We read the first triple assert_eq!(parser.base_iri(), Some("http://example.com/")); // There is now a base IRI. ``` -------------------------------- ### for_writer Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/serializer.rs.html?search=u32+-%3E+bool Initializes the serializer to write RDF data to a given `Write` implementation. This method returns a `WriterQuadSerializer` which is used for the actual serialization process. ```APIDOC ## for_writer ### Description Serializes to a [`Write`] implementation. Do not forget to run the [`finish`](WriterQuadSerializer::finish()) method to properly write the last bytes of the file. This writer does unbuffered writes. You might want to use [`BufWriter`](io::BufWriter) to avoid that. ### Method ```rust pub fn for_writer(self, writer: W) -> WriterQuadSerializer ``` ### Parameters * `writer` (W: Write) - The writer implementation to serialize RDF data to. ### Returns A `WriterQuadSerializer` instance ready for writing RDF data. ``` -------------------------------- ### Get RdfFormat Media Type Source: https://docs.rs/oxrdfio/latest/oxrdfio/enum.RdfFormat.html Retrieves the IANA media type for an RdfFormat variant. This is commonly used in HTTP headers and file type identification. ```rust use oxrdfio::RdfFormat; assert_eq!(RdfFormat::NTriples.media_type(), "application/n-triples") ``` -------------------------------- ### Retrieving Prefixes During RDF Parsing Source: https://docs.rs/oxrdfio/latest/src/oxrdfio/parser.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to retrieve prefixes declared in an RDF document during the parsing process using an async reader. Prefixes are available after at least one quad has been read. ```rust use oxrdfio::{RdfFormat, RdfParser}; let file = r#"@base . @prefix schema: . 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::>(), []); // No prefix at the beginning parser.next().await.unwrap()?; assert_eq!( parser.prefixes().collect::>(), [("schema", "http://schema.org/")] ); // There are now prefixes ``` -------------------------------- ### Get RdfFormat IRI Source: https://docs.rs/oxrdfio/latest/oxrdfio/enum.RdfFormat.html Retrieves the canonical IRI for an RdfFormat variant. This is useful for identifying formats according to the Unique URIs for file formats registry. ```rust use oxrdfio::RdfFormat; assert_eq!( RdfFormat::NTriples.iri(), "http://www.w3.org/ns/formats/N-Triples" ) ``` -------------------------------- ### Default Source: https://docs.rs/oxrdfio/latest/oxrdfio/struct.JsonLdProfileSet.html?search=std%3A%3Avec Provides a default JsonLdProfileSet, which is an empty set. ```APIDOC ## Default ### Description Returns the default value for `JsonLdProfileSet`, which is an empty set. ### Method `fn default() -> JsonLdProfileSet` ### Example ```rust use oxjsonld::JsonLdProfileSet; let profile_set: JsonLdProfileSet = Default::default(); ``` ```