From fed789315b269873c7ba957ec8a478997135c80c Mon Sep 17 00:00:00 2001 From: Simon Johnston Date: Mon, 16 Sep 2024 19:55:40 -0700 Subject: [PATCH] style: fix cfg's and remove empty comments --- rdftk_io/Cargo.toml | 4 +-- rdftk_io/src/common/indenter.rs | 9 ------ rdftk_io/src/common/mod.rs | 14 +++++---- rdftk_io/src/common/parser/n3.rs | 11 ------- rdftk_io/src/common/parser/nquads.rs | 2 -- rdftk_io/src/common/parser/ntriples.rs | 2 -- rdftk_io/src/common/parser/trig.rs | 11 ------- rdftk_io/src/common/parser/turtle.rs | 11 ------- rdftk_io/src/json/mod.rs | 15 ++++++++++ rdftk_io/src/json/reader.rs | 7 ----- rdftk_io/src/json/writer.rs | 18 ----------- rdftk_io/src/json_ld/reader.rs | 8 ----- rdftk_io/src/json_ld/writer.rs | 8 ----- rdftk_io/src/lib.rs | 21 ------------- rdftk_io/src/n3/mod.rs | 1 - rdftk_io/src/n3/writer.rs | 9 ------ rdftk_io/src/nq/mod.rs | 2 +- rdftk_io/src/nt/mod.rs | 2 +- rdftk_io/src/trig/writer.rs | 9 ------ rdftk_io/src/turtle/mod.rs | 41 ++++++++++++++++++++++++++ rdftk_io/src/turtle/writer/mod.rs | 25 ---------------- rdftk_io/src/xml/mod.rs | 2 +- rdftk_io/src/xml/reader.rs | 17 +++-------- rdftk_io/tests/read_json.rs | 2 ++ rdftk_io/tests/read_nq.rs | 2 ++ rdftk_io/tests/read_nt.rs | 2 ++ rdftk_io/tests/read_turtle.rs | 2 ++ rdftk_io/tests/read_xml.rs | 2 ++ rdftk_io/tests/w3c_nt.rs | 2 ++ 29 files changed, 86 insertions(+), 175 deletions(-) diff --git a/rdftk_io/Cargo.toml b/rdftk_io/Cargo.toml index 3ca7032..d872718 100644 --- a/rdftk_io/Cargo.toml +++ b/rdftk_io/Cargo.toml @@ -18,10 +18,10 @@ default = ["dot", "json", "json-ld", "n3", "nq", "nt", "trig", "turtle", "xml"] dot = [] json = ["serde_json"] json-ld = ["serde_json"] -n3 = [] +n3 = ["pest", "pest_derive"] nq = ["pest", "pest_derive"] nt = ["pest", "pest_derive"] -trig = [] +trig = ["pest", "pest_derive"] turtle = ["pest", "pest_derive"] xml = ["xml-rs", "rdftk_names"] diff --git a/rdftk_io/src/common/indenter.rs b/rdftk_io/src/common/indenter.rs index 885ca32..f66bb30 100644 --- a/rdftk_io/src/common/indenter.rs +++ b/rdftk_io/src/common/indenter.rs @@ -1,12 +1,3 @@ -/*! -One-line description. - -More detailed description, with - -# Example - -*/ - use std::fmt::{Display, Formatter}; // ------------------------------------------------------------------------------------------------ diff --git a/rdftk_io/src/common/mod.rs b/rdftk_io/src/common/mod.rs index 3c6b168..adbd4d9 100644 --- a/rdftk_io/src/common/mod.rs +++ b/rdftk_io/src/common/mod.rs @@ -1,9 +1,5 @@ /*! -One-line description. - -More detailed description, with - -# Example +Internal, common, code for reader and writer implementations. */ @@ -11,6 +7,14 @@ More detailed description, with // Modules // ------------------------------------------------------------------------------------------------ +#[cfg(feature = "nt")] pub(crate) mod indenter; +#[cfg(any( + feature = "n3", + feature = "nq", + feature = "nt", + feature = "trig", + feature = "turtle" +))] pub(crate) mod parser; diff --git a/rdftk_io/src/common/parser/n3.rs b/rdftk_io/src/common/parser/n3.rs index 3536722..4a39e0b 100644 --- a/rdftk_io/src/common/parser/n3.rs +++ b/rdftk_io/src/common/parser/n3.rs @@ -1,14 +1,3 @@ -/*! -One-line description. - -More detailed description, with - -# Example - -End of file during parsingSymbol’s value as variable is void: rustEnd of file during parsing - - */ - // use ... // ------------------------------------------------------------------------------------------------ diff --git a/rdftk_io/src/common/parser/nquads.rs b/rdftk_io/src/common/parser/nquads.rs index 5aafe68..b061b6c 100644 --- a/rdftk_io/src/common/parser/nquads.rs +++ b/rdftk_io/src/common/parser/nquads.rs @@ -1,5 +1,3 @@ -#![allow(clippy::upper_case_acronyms)] // << generated by pest. - use super::ntriples::{object as nt_object, predicate as nt_predicate, subject as nt_subject}; use super::Rule; use pest::iterators::Pair; diff --git a/rdftk_io/src/common/parser/ntriples.rs b/rdftk_io/src/common/parser/ntriples.rs index cfe0260..685a633 100644 --- a/rdftk_io/src/common/parser/ntriples.rs +++ b/rdftk_io/src/common/parser/ntriples.rs @@ -1,5 +1,3 @@ -#![allow(clippy::upper_case_acronyms)] // << generated by pest. - use super::Rule; use pest::iterators::Pair; use rdftk_core::error::Error; diff --git a/rdftk_io/src/common/parser/trig.rs b/rdftk_io/src/common/parser/trig.rs index 3536722..4a39e0b 100644 --- a/rdftk_io/src/common/parser/trig.rs +++ b/rdftk_io/src/common/parser/trig.rs @@ -1,14 +1,3 @@ -/*! -One-line description. - -More detailed description, with - -# Example - -End of file during parsingSymbol’s value as variable is void: rustEnd of file during parsing - - */ - // use ... // ------------------------------------------------------------------------------------------------ diff --git a/rdftk_io/src/common/parser/turtle.rs b/rdftk_io/src/common/parser/turtle.rs index 3536722..4a39e0b 100644 --- a/rdftk_io/src/common/parser/turtle.rs +++ b/rdftk_io/src/common/parser/turtle.rs @@ -1,14 +1,3 @@ -/*! -One-line description. - -More detailed description, with - -# Example - -End of file during parsingSymbol’s value as variable is void: rustEnd of file during parsing - - */ - // use ... // ------------------------------------------------------------------------------------------------ diff --git a/rdftk_io/src/json/mod.rs b/rdftk_io/src/json/mod.rs index 6d79b22..860f09c 100644 --- a/rdftk_io/src/json/mod.rs +++ b/rdftk_io/src/json/mod.rs @@ -1,6 +1,21 @@ /*! Provides for writing a `Graph` instance in the W3C [RDF 1.1 JSON Alternate Serialization (RDF/JSON)](https://www.w3.org/TR/rdf-json/) format. + +# Example Writer + +```rust +use rdftk_io::json::{JsonWriter, JsonOptions}; +# use objio::{HasOptions, ObjectWriter}; +# use rdftk_core::model::graph::GraphRef; +# fn make_graph() -> GraphRef { rdftk_core::simple::graph::graph_factory().graph() } + +let writer = JsonWriter::default() + .with_options(JsonOptions::default().with_pretty_print(true)); + +let result = writer.write_to_string(&make_graph()); +``` + */ // ------------------------------------------------------------------------------------------------ diff --git a/rdftk_io/src/json/reader.rs b/rdftk_io/src/json/reader.rs index aab2c59..f214e14 100644 --- a/rdftk_io/src/json/reader.rs +++ b/rdftk_io/src/json/reader.rs @@ -1,10 +1,3 @@ -/*! -Provides the `JsonReader` implementation of the `GraphReader` trait. - -# Example - -*/ - use crate::json::syntax::{ BNODE_PREFIX, OBJ_KEY_DATATYPE, OBJ_KEY_LANG, OBJ_KEY_TYPE, OBJ_KEY_VALUE, OBJ_TYPE_BNODE, OBJ_TYPE_LITERAL, OBJ_TYPE_URI, diff --git a/rdftk_io/src/json/writer.rs b/rdftk_io/src/json/writer.rs index 6134c6c..b27134f 100644 --- a/rdftk_io/src/json/writer.rs +++ b/rdftk_io/src/json/writer.rs @@ -1,21 +1,3 @@ -/*! -Provides the `JsonWriter` implementation of the `GraphWriter` trait. - -```rust -use rdftk_io::json::{JsonWriter, JsonOptions}; -# use objio::{HasOptions, ObjectWriter}; -# use rdftk_core::model::graph::GraphRef; -# fn make_graph() -> GraphRef { rdftk_core::simple::graph::graph_factory().graph() } - -let writer = JsonWriter::default() - .with_options(JsonOptions::default().with_pretty_print(true)); - -let result = writer.write_to_string(&make_graph()); -``` - - -*/ - use crate::json::syntax::{ OBJ_KEY_DATATYPE, OBJ_KEY_LANG, OBJ_KEY_TYPE, OBJ_KEY_VALUE, OBJ_TYPE_BNODE, OBJ_TYPE_LITERAL, OBJ_TYPE_URI, diff --git a/rdftk_io/src/json_ld/reader.rs b/rdftk_io/src/json_ld/reader.rs index 1f52a31..b12262d 100644 --- a/rdftk_io/src/json_ld/reader.rs +++ b/rdftk_io/src/json_ld/reader.rs @@ -1,11 +1,3 @@ -/*! -One-line description. - -More detailed description, with - -# Example - -*/ // use ... diff --git a/rdftk_io/src/json_ld/writer.rs b/rdftk_io/src/json_ld/writer.rs index 1f52a31..b12262d 100644 --- a/rdftk_io/src/json_ld/writer.rs +++ b/rdftk_io/src/json_ld/writer.rs @@ -1,11 +1,3 @@ -/*! -One-line description. - -More detailed description, with - -# Example - -*/ // use ... diff --git a/rdftk_io/src/lib.rs b/rdftk_io/src/lib.rs index bc949f6..0a98e7e 100644 --- a/rdftk_io/src/lib.rs +++ b/rdftk_io/src/lib.rs @@ -24,24 +24,6 @@ creation of [GraphViz](https://graphviz.gitlab.io/) dot files for a visualizatio Each module will also provide public constants `NAME`, `FILE_EXTENSION`, and `MIME_TYPE`. -# Example - -An example, reading an existing NTriple file. - -```rust -use objio::{HasOptions, ObjectReader}; -use rdftk_io::nt::{NTripleReaderOptions, NTripleReader}; -use rdftk_core::simple::graph_factory; -use std::fs::File; -use std::path::PathBuf; - -let file_path = PathBuf::from("tests/w3c/nt/literal.nt"); -let mut file = File::open(file_path).unwrap(); -let reader = NTripleReader::default() - .with_options(NTripleReaderOptions::default().with_factory(graph_factory())); -let graph = reader.read(&mut file).unwrap(); -``` - */ #![warn( @@ -97,7 +79,6 @@ pub mod dot; pub mod json; #[cfg(feature = "n3")] -#[doc(hidden)] pub mod n3; #[cfg(feature = "nq")] @@ -107,11 +88,9 @@ pub mod nq; pub mod nt; #[cfg(feature = "trig")] -#[doc(hidden)] pub mod trig; #[cfg(feature = "turtle")] -#[doc(hidden)] pub mod turtle; #[cfg(feature = "xml")] diff --git a/rdftk_io/src/n3/mod.rs b/rdftk_io/src/n3/mod.rs index 923b436..2fb12b1 100644 --- a/rdftk_io/src/n3/mod.rs +++ b/rdftk_io/src/n3/mod.rs @@ -4,7 +4,6 @@ proposed W3C [Notation3 (N3)](https://www.w3.org/TeamSubmission/n3/), _a readabl format. */ - // ------------------------------------------------------------------------------------------------ // Public Values // ------------------------------------------------------------------------------------------------ diff --git a/rdftk_io/src/n3/writer.rs b/rdftk_io/src/n3/writer.rs index 1f52a31..b21ffbc 100644 --- a/rdftk_io/src/n3/writer.rs +++ b/rdftk_io/src/n3/writer.rs @@ -1,12 +1,3 @@ -/*! -One-line description. - -More detailed description, with - -# Example - -*/ - // use ... // ------------------------------------------------------------------------------------------------ diff --git a/rdftk_io/src/nq/mod.rs b/rdftk_io/src/nq/mod.rs index d8f9ad0..7d62a72 100644 --- a/rdftk_io/src/nq/mod.rs +++ b/rdftk_io/src/nq/mod.rs @@ -6,7 +6,7 @@ format. Provides the `NQuadDataSetWriter` implementation of the `DataSetWriter` trait and the `NQuadGraphWriter` implementation of the `GraphWriter` trait. -# Example +# Example Writer ```rust use rdftk_io::nq::NQuadWriter; diff --git a/rdftk_io/src/nt/mod.rs b/rdftk_io/src/nt/mod.rs index 38cac80..15bdee5 100644 --- a/rdftk_io/src/nt/mod.rs +++ b/rdftk_io/src/nt/mod.rs @@ -4,7 +4,7 @@ W3C [RDF 1.1 N-Triples](https://www.w3.org/TR/n-triples/), _a line-based syntax format. -# Writer Example +# Example Writer ```rust use rdftk_io::nt::NTripleWriter; diff --git a/rdftk_io/src/trig/writer.rs b/rdftk_io/src/trig/writer.rs index df62a8d..b158504 100644 --- a/rdftk_io/src/trig/writer.rs +++ b/rdftk_io/src/trig/writer.rs @@ -1,12 +1,3 @@ -/*! -One-line description. - -More detailed description, with - -# Example - -*/ - use crate::turtle::TurtleOptions; use objio::{impl_has_options, HasOptions, ObjectWriter}; use rdftk_core::error::Error; diff --git a/rdftk_io/src/turtle/mod.rs b/rdftk_io/src/turtle/mod.rs index 2b75eca..fe8140a 100644 --- a/rdftk_io/src/turtle/mod.rs +++ b/rdftk_io/src/turtle/mod.rs @@ -2,6 +2,47 @@ Provides for reading and writing a `Graph` instance in the [RDF 1.1 Turtle](https://www.w3.org/TR/turtle/), _Terse RDF Triple Language_, format. + +# Example Writer + +An example, reading an existing NTriple file. + +```rust +use objio::{HasOptions, ObjectReader}; +use rdftk_io::nt::{NTripleReaderOptions, NTripleReader}; +use rdftk_core::simple::graph_factory; +use std::fs::File; +use std::path::PathBuf; + +let file_path = PathBuf::from("tests/w3c/nt/literal.nt"); +let mut file = File::open(file_path).unwrap(); +let reader = NTripleReader::default() + .with_options(NTripleReaderOptions::default().with_factory(graph_factory())); +let graph = reader.read(&mut file).unwrap(); +``` + + +# Example Writer with Options + +```rust +use rdftk_io::turtle::{TurtleWriter, TurtleOptions}; +use rdftk_iri::{IriRef, Iri}; +use std::str::FromStr; +# use objio::{HasOptions, ObjectWriter}; +# use rdftk_core::model::graph::GraphRef; +# fn make_graph() -> GraphRef { rdftk_core::simple::graph::graph_factory().graph() } + +let mut options = TurtleOptions::default() + .with_id_base(Iri::from_str("http://en.wikipedia.org/wiki/").unwrap().into()) + .with_sparql_style() + .without_nested_blank_nodes(); + +let writer = TurtleWriter::default() + .with_options(options); + +let result = writer.write_to_string(&make_graph()); +``` + */ // ------------------------------------------------------------------------------------------------ diff --git a/rdftk_io/src/turtle/writer/mod.rs b/rdftk_io/src/turtle/writer/mod.rs index b74b77a..d6f3e27 100644 --- a/rdftk_io/src/turtle/writer/mod.rs +++ b/rdftk_io/src/turtle/writer/mod.rs @@ -1,28 +1,3 @@ -/*! -Provides the `TurtleWriter` implementation of the `GraphWriter` trait. - -# Example - -```rust -use rdftk_io::turtle::{TurtleWriter, TurtleOptions}; -use rdftk_iri::{IriRef, Iri}; -use std::str::FromStr; -# use objio::{HasOptions, ObjectWriter}; -# use rdftk_core::model::graph::GraphRef; -# fn make_graph() -> GraphRef { rdftk_core::simple::graph::graph_factory().graph() } - -let mut options = TurtleOptions::default() - .with_id_base(Iri::from_str("http://en.wikipedia.org/wiki/").unwrap().into()) - .with_sparql_style() - .without_nested_blank_nodes(); - -let writer = TurtleWriter::default() - .with_options(options); - -let result = writer.write_to_string(&make_graph()); -``` -*/ - // ------------------------------------------------------------------------------------------------ // Modules // ------------------------------------------------------------------------------------------------ diff --git a/rdftk_io/src/xml/mod.rs b/rdftk_io/src/xml/mod.rs index c25324e..782d182 100644 --- a/rdftk_io/src/xml/mod.rs +++ b/rdftk_io/src/xml/mod.rs @@ -2,7 +2,7 @@ Provides for writing out in the [RDF 1.1 XML Syntax](https://www.w3.org/TR/rdf-syntax-grammar/) format. -# Writer Example +# Example Writer This writer has a number of options, it can be written in a plain, streaming, form or alternatively pretty-printed for readability. It is also possible to pick one of the type styles described diff --git a/rdftk_io/src/xml/reader.rs b/rdftk_io/src/xml/reader.rs index c501784..965e4f6 100644 --- a/rdftk_io/src/xml/reader.rs +++ b/rdftk_io/src/xml/reader.rs @@ -1,16 +1,3 @@ -/*! -Provides the `XmlReader` implementation of the `GraphReader` trait. - -# Example - -*/ - -// use ... - -// ------------------------------------------------------------------------------------------------ -// Public Types -// ------------------------------------------------------------------------------------------------ - use crate::xml::syntax::{ ATTRIBUTE_ABOUT, ATTRIBUTE_ID, ATTRIBUTE_NODE_ID, ATTRIBUTE_PARSE_TYPE, ATTRIBUTE_RESOURCE, ATTRIBUTE_XML_BASE, ATTRIBUTE_XML_LANG, ELEMENT_DESCRIPTION, ELEMENT_RDF, @@ -32,6 +19,10 @@ use xml::name::OwnedName; use xml::reader::XmlEvent; use xml::{EventReader, EventWriter}; +// ------------------------------------------------------------------------------------------------ +// Public Types +// ------------------------------------------------------------------------------------------------ + /// /// An implementation of the GraphReader trait to read resources in the XML representation. /// diff --git a/rdftk_io/tests/read_json.rs b/rdftk_io/tests/read_json.rs index ba8d98b..ed7a3ab 100644 --- a/rdftk_io/tests/read_json.rs +++ b/rdftk_io/tests/read_json.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "json")] + use objio::ObjectReader; use rdftk_io::json::JsonReader; diff --git a/rdftk_io/tests/read_nq.rs b/rdftk_io/tests/read_nq.rs index 432c426..0961028 100644 --- a/rdftk_io/tests/read_nq.rs +++ b/rdftk_io/tests/read_nq.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "nq")] + use objio::ObjectReader; use rdftk_io::nq::NQuadReader; diff --git a/rdftk_io/tests/read_nt.rs b/rdftk_io/tests/read_nt.rs index 525cae3..04d47e6 100644 --- a/rdftk_io/tests/read_nt.rs +++ b/rdftk_io/tests/read_nt.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "nt")] + use objio::{ObjectReader, ObjectWriter}; use rdftk_core::{error::Error, model::graph::GraphRef}; use rdftk_io::nt::{NTripleReader, NTripleWriter}; diff --git a/rdftk_io/tests/read_turtle.rs b/rdftk_io/tests/read_turtle.rs index 640d588..c68ffb8 100644 --- a/rdftk_io/tests/read_turtle.rs +++ b/rdftk_io/tests/read_turtle.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "turtle")] + use objio::ObjectReader; use rdftk_core::{error::Error, model::graph::GraphRef}; use rdftk_io::turtle::TurtleReader; diff --git a/rdftk_io/tests/read_xml.rs b/rdftk_io/tests/read_xml.rs index 36ef253..3158f2f 100644 --- a/rdftk_io/tests/read_xml.rs +++ b/rdftk_io/tests/read_xml.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "xml")] + use objio::ObjectReader; use rdftk_io::xml::XmlReader; diff --git a/rdftk_io/tests/w3c_nt.rs b/rdftk_io/tests/w3c_nt.rs index fb86dd9..d714750 100644 --- a/rdftk_io/tests/w3c_nt.rs +++ b/rdftk_io/tests/w3c_nt.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "nt")] + use objio::ObjectReader; use rdftk_core::error::eprint_trace; use rdftk_core::model::graph::GraphRef;