From 5039da163b1ebd0f0d35502282aaf0b0b0bd254a Mon Sep 17 00:00:00 2001 From: Tpt Date: Wed, 24 Jun 2020 10:18:50 +0200 Subject: [PATCH] Small code cleanup --- lib/src/error.rs | 4 ++-- lib/src/lib.rs | 13 ++++++------- lib/src/model/blank_node.rs | 2 +- lib/src/model/graph.rs | 4 ++-- lib/src/model/literal.rs | 12 ++++++------ lib/src/model/mod.rs | 2 +- lib/src/model/named_node.rs | 6 +++--- lib/src/model/triple.rs | 6 +++--- lib/src/sparql/plan_builder.rs | 2 +- lib/src/store/mod.rs | 2 +- lib/src/store/rocksdb.rs | 4 ++-- 11 files changed, 28 insertions(+), 29 deletions(-) diff --git a/lib/src/error.rs b/lib/src/error.rs index dccdf55f..2ff9e797 100644 --- a/lib/src/error.rs +++ b/lib/src/error.rs @@ -10,7 +10,7 @@ use std::string::FromUtf8Error; /// The Oxigraph error type. /// -/// The `wrap` method allows to make this type wrap any implementation of `std::error::Error`. +/// The `wrap` method allows us to make this type wrap any implementation of `std::error::Error`. /// This type also avoids heap allocations for the most common cases of Oxigraph errors. #[derive(Debug)] pub struct Error { @@ -44,7 +44,7 @@ impl error::Error for Error { } impl Error { - /// Wraps an other error. + /// Wraps another error. pub fn wrap(error: impl error::Error + Send + Sync + 'static) -> Self { Self { inner: ErrorKind::Other(Box::new(error)), diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 1cb42a66..e77e93eb 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -6,11 +6,11 @@ //! * `MemoryStore`: a simple in memory implementation. //! * `RocksDbStore`: a file system implementation based on the [RocksDB](https://rocksdb.org/) key-value store. //! It requires the `"rocksdb"` feature to be activated. -//! It also requires the clang](https://clang.llvm.org/) compiler to be installed. -//! * `SledStore`: an other file system implementation based on the [Sled](https://sled.rs/) key-value store. +//! It also requires the [clang](https://clang.llvm.org/) compiler to be installed. +//! * `SledStore`: another file system implementation based on the [Sled](https://sled.rs/) key-value store. //! It requires the `"sled"` feature to be activated. //! Sled is much faster to build than RockDB and does not require a C++ compiler. -//! However Sled is still in heavy developpment, less tested and data load seems much slower than RocksDB. +//! However, Sled is still in developpment, less tested and data load seems much slower than RocksDB. //! //! Usage example with the `MemoryStore`: //! @@ -90,7 +90,6 @@ clippy::print_stdout, clippy::pub_enum_variant_names, //TODO clippy::redundant_closure_for_method_calls, - clippy::replace_consts, clippy::result_map_unwrap_or_else, // clippy::shadow_reuse, // clippy::shadow_same, @@ -115,11 +114,11 @@ mod syntax; pub use error::Error; pub type Result = ::std::result::Result; -pub use crate::store::MemoryStore; +pub use crate::store::memory::MemoryStore; #[cfg(feature = "rocksdb")] -pub use crate::store::RocksDbStore; +pub use crate::store::rocksdb::RocksDbStore; #[cfg(feature = "sled")] -pub use crate::store::SledStore; +pub use crate::store::sled::SledStore; pub use crate::syntax::DatasetSyntax; pub use crate::syntax::FileSyntax; pub use crate::syntax::GraphSyntax; diff --git a/lib/src/model/blank_node.rs b/lib/src/model/blank_node.rs index 4d746171..f1aed6bd 100644 --- a/lib/src/model/blank_node.rs +++ b/lib/src/model/blank_node.rs @@ -4,7 +4,7 @@ use std::fmt; use std::io::Write; use std::str; -/// A RDF [blank node](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node). +/// An RDF [blank node](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node). /// /// This implementation enforces that the blank node id is a uniquely generated ID to easily ensure /// that it is not possible for two blank nodes to share an id. diff --git a/lib/src/model/graph.rs b/lib/src/model/graph.rs index 7c7c5fdf..71413e80 100644 --- a/lib/src/model/graph.rs +++ b/lib/src/model/graph.rs @@ -128,9 +128,9 @@ impl SimpleGraph { self.triples.is_empty() } - /// Checks if the current graph is [isomorphic](https://www.w3.org/TR/rdf11-concepts/#dfn-graph-isomorphism) with an other one + /// Checks if the current graph is [isomorphic](https://www.w3.org/TR/rdf11-concepts/#dfn-graph-isomorphism) with another one /// - /// Warning: This algorithm as a worst case complexity in n! + /// Warning: This algorithm worst case complexity is in O(n!) pub fn is_isomorphic(&self, other: &SimpleGraph) -> bool { are_graphs_isomorphic(self, other) } diff --git a/lib/src/model/literal.rs b/lib/src/model/literal.rs index a5443023..100127f0 100644 --- a/lib/src/model/literal.rs +++ b/lib/src/model/literal.rs @@ -8,7 +8,7 @@ use std::borrow::Cow; use std::fmt; use std::option::Option; -/// A RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal) +/// An RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal) /// /// The default string formatter is returning a N-Triples, Turtle and SPARQL compatible representation: /// ``` @@ -43,12 +43,12 @@ enum LiteralContent { } impl Literal { - /// Builds a RDF [simple literal](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal) + /// Builds an RDF [simple literal](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal) pub fn new_simple_literal(value: impl Into) -> Self { Literal(LiteralContent::String(value.into())) } - /// Builds a RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal) with a [datatype](https://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri) + /// Builds an RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal) with a [datatype](https://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri) pub fn new_typed_literal(value: impl Into, datatype: impl Into) -> Self { let value = value.into(); let datatype = datatype.into(); @@ -59,7 +59,7 @@ impl Literal { }) } - /// Builds a RDF [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) + /// Builds an RDF [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) pub fn new_language_tagged_literal( value: impl Into, language: impl Into, @@ -72,7 +72,7 @@ impl Literal { })) } - /// Builds a RDF [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) + /// Builds an RDF [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) /// /// It is the responsibility of the caller to check that `language` /// is valid [BCP47](https://tools.ietf.org/html/bcp47) language tag, @@ -122,7 +122,7 @@ impl Literal { } } - /// Checks if it could be considered as an RDF 1.0 [plain literal](https://www.w3.org/TR/rdf-concepts/#dfn-plain-literal). + /// Checks if this lieteral could be seen as an RDF 1.0 [plain literal](https://www.w3.org/TR/rdf-concepts/#dfn-plain-literal). /// /// It returns true if the literal is a [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) /// or has the datatype [xsd:string](http://www.w3.org/2001/XMLSchema#string). diff --git a/lib/src/model/mod.rs b/lib/src/model/mod.rs index 76effb32..50dffee1 100644 --- a/lib/src/model/mod.rs +++ b/lib/src/model/mod.rs @@ -1,6 +1,6 @@ //! Implements data structures for [RDF 1.1 Concepts](https://www.w3.org/TR/rdf11-concepts/). //! -//! Inspired by [RDFjs](http://rdf.js.org/) and [Apache Commons RDF](http://commons.apache.org/proper/commons-rdf/) +//! Inspired by [RDF/JS](https://rdf.js.org/data-model-spec/) and [Apache Commons RDF](http://commons.apache.org/proper/commons-rdf/) mod blank_node; mod graph; diff --git a/lib/src/model/named_node.rs b/lib/src/model/named_node.rs index 749c199d..28851650 100644 --- a/lib/src/model/named_node.rs +++ b/lib/src/model/named_node.rs @@ -2,7 +2,7 @@ use oxiri::{Iri, IriParseError}; use rio_api::model as rio; use std::fmt; -/// A RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) +/// An RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) /// /// The default string formatter is returning a N-Triples, Turtle and SPARQL compatible representation: /// ``` @@ -19,7 +19,7 @@ pub struct NamedNode { } impl NamedNode { - /// Builds and validate a RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) + /// Builds and validate an RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) pub fn parse(iri: impl Into) -> Result { Ok(Self::new_from_iri(Iri::parse(iri.into())?)) } @@ -28,7 +28,7 @@ impl NamedNode { Self::new_unchecked(iri.into_inner()) } - /// Builds a RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) from a string. + /// Builds an RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) from a string. /// /// It is the caller's responsibility to ensure that `iri` is a valid IRI. /// diff --git a/lib/src/model/triple.rs b/lib/src/model/triple.rs index 1ec60799..6b2d0dfa 100644 --- a/lib/src/model/triple.rs +++ b/lib/src/model/triple.rs @@ -57,7 +57,7 @@ impl<'a> From<&'a NamedOrBlankNode> for rio::NamedOrBlankNode<'a> { } } -/// A RDF [term](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term) +/// An RDF [term](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term) /// It is the union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri), [blank nodes](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node) and [literals](https://www.w3.org/TR/rdf11-concepts/#dfn-literal). #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] pub enum Term { @@ -148,7 +148,7 @@ pub struct Triple { } impl Triple { - /// Builds a RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) + /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) pub fn new( subject: impl Into, predicate: impl Into, @@ -228,7 +228,7 @@ pub struct Quad { } impl Quad { - /// Builds a RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) + /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) pub fn new( subject: impl Into, predicate: impl Into, diff --git a/lib/src/sparql/plan_builder.rs b/lib/src/sparql/plan_builder.rs index ac6ab8c7..913643f6 100644 --- a/lib/src/sparql/plan_builder.rs +++ b/lib/src/sparql/plan_builder.rs @@ -981,7 +981,7 @@ fn bnode_key(blank_nodes: &mut Vec, blank_node: &BlankNode) -> usize match slice_key(blank_nodes, blank_node) { Some(key) => key, None => { - blank_nodes.push(blank_node.clone()); + blank_nodes.push(*blank_node); blank_nodes.len() - 1 } } diff --git a/lib/src/store/mod.rs b/lib/src/store/mod.rs index 742d11b8..108772af 100644 --- a/lib/src/store/mod.rs +++ b/lib/src/store/mod.rs @@ -1,7 +1,7 @@ //! RDF quads storage implementations. //! //! They encode a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) -//! and allow to query and update it using SPARQL. +//! and allow querying and updating them using SPARQL. pub mod memory; pub(crate) mod numeric_encoder; diff --git a/lib/src/store/rocksdb.rs b/lib/src/store/rocksdb.rs index 593f26b3..a50991f0 100644 --- a/lib/src/store/rocksdb.rs +++ b/lib/src/store/rocksdb.rs @@ -159,7 +159,7 @@ impl RocksDbStore { /// Executes a transaction. /// /// The transaction is executed if the given closure returns `Ok`. - /// Nothing is done if the clusre returns `Err`. + /// Nothing is done if the closure returns `Err`. /// /// See `MemoryStore` for a usage example. pub fn transaction<'a>( @@ -691,7 +691,7 @@ impl RocksDbInnerTransaction<'_> { #[allow(clippy::option_expect_used)] fn get_cf<'a>(db: &'a DB, name: &str) -> &'a ColumnFamily { db.cf_handle(name) - .expect("A column family that should exists in RocksDB does not exists") + .expect("A column family that should exist in RocksDB does not exist") } fn encode_term(t: EncodedTerm) -> Vec {