From 4e0af5fe0a9cc609ae287593baf7f7f60b75ef31 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Wed, 17 Jul 2024 14:54:08 -0500 Subject: [PATCH 01/20] init commit --- api/src/dataset.rs | 2 +- api/src/graph.rs | 2 +- api/src/source.rs | 4 ++-- api/src/term.rs | 2 +- inmem/src/dataset.rs | 4 ++-- inmem/src/index.rs | 2 +- rio/src/parser.rs | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api/src/dataset.rs b/api/src/dataset.rs index 81878d5a..8b4b00dc 100644 --- a/api/src/dataset.rs +++ b/api/src/dataset.rs @@ -56,7 +56,7 @@ pub trait Dataset { where Self: 'x; /// The error type that this dataset may raise. - type Error: Error + 'static; + type Error: Error + 'static + Send + Sync; /// An iterator visiting all quads of this dataset in arbitrary order. /// diff --git a/api/src/graph.rs b/api/src/graph.rs index f94432c6..631b46aa 100644 --- a/api/src/graph.rs +++ b/api/src/graph.rs @@ -53,7 +53,7 @@ pub trait Graph { where Self: 'x; /// The error type that this graph may raise. - type Error: Error + 'static; + type Error: Error + 'static + Send + Sync; /// An iterator visiting all triples of this graph in arbitrary order. /// diff --git a/api/src/source.rs b/api/src/source.rs index a90219a2..22a78497 100644 --- a/api/src/source.rs +++ b/api/src/source.rs @@ -87,7 +87,7 @@ pub trait Source { /// The type of items this source yields. type Item<'x>; /// The type of errors produced by this source. - type Error: Error + 'static; + type Error: Error + 'static + Send + Sync; /// Call f for some item(s) (possibly zero) from this source, if any. /// @@ -200,7 +200,7 @@ pub trait Source { impl<'a, I, T, E> Source for I where I: Iterator> + 'a, - E: Error + 'static, + E: Error + 'static + Send + Sync, { type Item<'x> = T; type Error = E; diff --git a/api/src/term.rs b/api/src/term.rs index 9348e15f..d51e928d 100644 --- a/api/src/term.rs +++ b/api/src/term.rs @@ -575,7 +575,7 @@ pub trait FromTerm: Sized { /// See also [`FromTerm`] pub trait TryFromTerm: Sized { /// The error type produced when failing to copy a given term - type Error: 'static + std::error::Error; + type Error: 'static + std::error::Error + Send + Sync; /// Try to copy `term` into an instance of this type. fn try_from_term(term: T) -> Result; } diff --git a/inmem/src/dataset.rs b/inmem/src/dataset.rs index e537f84b..ee81b14f 100644 --- a/inmem/src/dataset.rs +++ b/inmem/src/dataset.rs @@ -14,7 +14,7 @@ use _iter::*; /// A dataset with a single quad index (GSPO). /// Fast to load but slow on some queries, with a relatively low memory footprint. -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, PartialEq)] pub struct GenericLightDataset { terms: TI, quads: BTreeSet<[TI::Index; 4]>, @@ -194,7 +194,7 @@ impl SetDataset for GenericLightDataset {} /// A heavily indexed dataset. /// Fast to query but slow to load, with a relatively high memory footprint. -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, PartialEq)] pub struct GenericFastDataset { terms: TI, gspo: BTreeSet<[TI::Index; 4]>, diff --git a/inmem/src/index.rs b/inmem/src/index.rs index 6177e558..0f1df6ed 100644 --- a/inmem/src/index.rs +++ b/inmem/src/index.rs @@ -64,7 +64,7 @@ pub trait TermIndex { /// The type of [indices](Index) used by this [`TermIndex`] type Index: Index; /// The type of error that this [`TermIndex`] may raise - type Error: Error + 'static; + type Error: Error + 'static + Send + Sync; /// Get the index corresponding to term `t`, if it exists. /// diff --git a/rio/src/parser.rs b/rio/src/parser.rs index fb2edb90..4282477c 100644 --- a/rio/src/parser.rs +++ b/rio/src/parser.rs @@ -17,7 +17,7 @@ pub struct StrictRioTripleSource(pub T); impl sophia_api::source::Source for StrictRioTripleSource where T: rio_api::parser::TriplesParser, - T::Error: Error + 'static, + T::Error: Error + 'static + Send + Sync, { type Item<'x> = Trusted>; @@ -50,7 +50,7 @@ pub struct StrictRioQuadSource(pub T); impl sophia_api::source::Source for StrictRioQuadSource where T: rio_api::parser::QuadsParser, - T::Error: Error + 'static, + T::Error: Error + 'static + Send + Sync, { type Item<'x> = Trusted>; @@ -83,7 +83,7 @@ pub struct GeneralizedRioSource(pub T); impl sophia_api::source::Source for GeneralizedRioSource where T: rio_api::parser::GeneralizedQuadsParser, - T::Error: Error + 'static, + T::Error: Error + 'static + Send + Sync, { type Item<'x> = Trusted>; From 597327d57da30d091f3f709d22589aaa11879289 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Wed, 17 Jul 2024 15:03:14 -0500 Subject: [PATCH 02/20] revert derive --- inmem/src/dataset.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inmem/src/dataset.rs b/inmem/src/dataset.rs index ee81b14f..e537f84b 100644 --- a/inmem/src/dataset.rs +++ b/inmem/src/dataset.rs @@ -14,7 +14,7 @@ use _iter::*; /// A dataset with a single quad index (GSPO). /// Fast to load but slow on some queries, with a relatively low memory footprint. -#[derive(Clone, Debug, Default, PartialEq)] +#[derive(Clone, Debug, Default)] pub struct GenericLightDataset { terms: TI, quads: BTreeSet<[TI::Index; 4]>, @@ -194,7 +194,7 @@ impl SetDataset for GenericLightDataset {} /// A heavily indexed dataset. /// Fast to query but slow to load, with a relatively high memory footprint. -#[derive(Clone, Debug, Default, PartialEq)] +#[derive(Clone, Debug, Default)] pub struct GenericFastDataset { terms: TI, gspo: BTreeSet<[TI::Index; 4]>, From 6fbf401fb527a85b5b1150b45c1a7960221a02bd Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Tue, 23 Jul 2024 20:00:41 -0500 Subject: [PATCH 03/20] resource is send + sync --- resource/src/resource/_error.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resource/src/resource/_error.rs b/resource/src/resource/_error.rs index 5c8be7eb..13b6628f 100644 --- a/resource/src/resource/_error.rs +++ b/resource/src/resource/_error.rs @@ -5,7 +5,7 @@ use std::fmt; /// An error raised when creating a [`Resource`](crate::Resource) #[derive(Debug)] -pub enum ResourceError { +pub enum ResourceError { /// The IRI is not absolute (an can therefore not be dereferenced) IriNotAbsolute(IriRef>), /// The resource could not be loaded @@ -70,7 +70,7 @@ pub enum ResourceError { }, } -impl ResourceError { +impl ResourceError { /// The identifier of the resource raising the error. /// /// NB: for errors raised during creation ([`ResourceError::IriNotAbsolute`], [`ResourceError::LoaderError`]), @@ -91,19 +91,19 @@ impl ResourceError { } } -impl fmt::Display for ResourceError { +impl fmt::Display for ResourceError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } } -impl From for ResourceError { +impl From for ResourceError { fn from(value: crate::loader::LoaderError) -> Self { Self::LoaderError(value) } } -impl Error for ResourceError {} +impl Error for ResourceError {} /// A result whose error is a [`ResourceError`] pub type ResourceResult = Result::Error>>; From 2ff36c9b7cf4ec2991ee4132dba1961ed7c392d8 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Tue, 23 Jul 2024 20:17:39 -0500 Subject: [PATCH 04/20] added threadsafe contracints to resource error --- resource/src/lib.rs | 2 +- resource/src/loader/_error.rs | 2 +- resource/src/resource/_error.rs | 7 +++++-- resource/src/resource/_struct.rs | 1 + resource/src/resource/test.rs | 4 +++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/resource/src/lib.rs b/resource/src/lib.rs index 508961d5..3aff4c93 100644 --- a/resource/src/lib.rs +++ b/resource/src/lib.rs @@ -72,7 +72,7 @@ mod test { pub const F5_LEN: usize = 20; pub type MyGraph = Vec<[SimpleTerm<'static>; 3]>; - pub type TestResult = Result<(), Box>; + pub type TestResult = Result<(), Box>; pub fn make_loader() -> LocalLoader { let ns = NS.map_unchecked(MownStr::from); diff --git a/resource/src/loader/_error.rs b/resource/src/loader/_error.rs index 7368f477..f33febd0 100644 --- a/resource/src/loader/_error.rs +++ b/resource/src/loader/_error.rs @@ -20,7 +20,7 @@ pub enum LoaderError { CantGuessSyntax(IriBuf), /// An error was encountered while parsing the data into an RDF graph #[error("Can not parse {0:?}: {1}")] - ParseError(IriBuf, Box), + ParseError(IriBuf, Box), } impl LoaderError { diff --git a/resource/src/resource/_error.rs b/resource/src/resource/_error.rs index 13b6628f..125786d5 100644 --- a/resource/src/resource/_error.rs +++ b/resource/src/resource/_error.rs @@ -70,7 +70,10 @@ pub enum ResourceError { }, } -impl ResourceError { +impl ResourceError +where + Self: Send + Sync + 'static, +{ /// The identifier of the resource raising the error. /// /// NB: for errors raised during creation ([`ResourceError::IriNotAbsolute`], [`ResourceError::LoaderError`]), @@ -103,7 +106,7 @@ impl From for Reso } } -impl Error for ResourceError {} +impl Error for ResourceError where Self: Send + Sync + 'static {} /// A result whose error is a [`ResourceError`] pub type ResourceResult = Result::Error>>; diff --git a/resource/src/resource/_struct.rs b/resource/src/resource/_struct.rs index 5860800f..fd2062ca 100644 --- a/resource/src/resource/_struct.rs +++ b/resource/src/resource/_struct.rs @@ -22,6 +22,7 @@ pub struct Resource { impl Resource where G: Graph + 'static, + G::Error: Send + Sync + 'static, L: Loader, { /// Constructor diff --git a/resource/src/resource/test.rs b/resource/src/resource/test.rs index 56948db5..467744ad 100644 --- a/resource/src/resource/test.rs +++ b/resource/src/resource/test.rs @@ -597,6 +597,8 @@ fn no_reload() -> TestResult { Ok(()) } -fn make_rsc(iri: Iri<&str>) -> Result, Box> { +fn make_rsc( + iri: Iri<&str>, +) -> Result, Box> { Ok(make_loader().arced().get_resource(iri)?) } From 6456ab6ed31dfcca6ced499765a0ec06eee500de Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Wed, 24 Jul 2024 16:14:01 -0500 Subject: [PATCH 05/20] handle xsd::decimal --- api/src/term/_native_literal.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/api/src/term/_native_literal.rs b/api/src/term/_native_literal.rs index 4410c178..1b301cee 100644 --- a/api/src/term/_native_literal.rs +++ b/api/src/term/_native_literal.rs @@ -235,6 +235,7 @@ impl TryFromTerm for f64 { if let Some(lex) = term.lexical_form() { if Term::eq(&term.datatype().unwrap(), xsd::double) || Term::eq(&term.datatype().unwrap(), xsd::float) + || Term::eq(&term.datatype().unwrap(), xsd::decimal) { lex.parse() } else { From 64e60f8ede42838e364146aac25967fb098c264c Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 12:58:03 -0500 Subject: [PATCH 06/20] updated with feature flag --- api/Cargo.toml | 1 + api/src/dataset.rs | 4 ++-- api/src/graph.rs | 4 ++-- api/src/lib.rs | 2 ++ api/src/source.rs | 6 +++--- api/src/term.rs | 2 +- inmem/src/index.rs | 6 +++--- iri/Cargo.toml | 1 + iri/src/lib.rs | 9 +++++++++ resource/src/lib.rs | 4 ++-- resource/src/resource/_error.rs | 13 ++++++------- resource/src/resource/_struct.rs | 3 ++- resource/src/resource/test.rs | 4 +--- rio/src/parser.rs | 8 ++++---- 14 files changed, 39 insertions(+), 28 deletions(-) diff --git a/api/Cargo.toml b/api/Cargo.toml index a9cb4b91..477ff2c3 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -23,6 +23,7 @@ all_tests = [] test_macro = [] # This feature (enabled by default) makes prefixes seralizable/deserializable serde = ["dep:serde"] +threadsafe_err = ["sophia_iri/threadsafe_err"] [dependencies] diff --git a/api/src/dataset.rs b/api/src/dataset.rs index 8b4b00dc..8405c5c5 100644 --- a/api/src/dataset.rs +++ b/api/src/dataset.rs @@ -12,8 +12,8 @@ use crate::quad::{iter_spog, Quad}; use crate::source::{IntoSource, QuadSource, StreamResult}; use crate::term::matcher::{GraphNameMatcher, TermMatcher}; use crate::term::{GraphName, SimpleTerm, Term}; +use crate::Error; use resiter::{filter::*, filter_map::*, flat_map::*, map::*}; -use std::error::Error; mod _foreign_impl; pub mod adapter; @@ -56,7 +56,7 @@ pub trait Dataset { where Self: 'x; /// The error type that this dataset may raise. - type Error: Error + 'static + Send + Sync; + type Error: Error + 'static; /// An iterator visiting all quads of this dataset in arbitrary order. /// diff --git a/api/src/graph.rs b/api/src/graph.rs index 631b46aa..83df2324 100644 --- a/api/src/graph.rs +++ b/api/src/graph.rs @@ -9,8 +9,8 @@ use crate::dataset::adapter::GraphAsDataset; use crate::source::{IntoSource, StreamResult, TripleSource}; use crate::term::{matcher::TermMatcher, SimpleTerm, Term}; use crate::triple::Triple; +use crate::Error; use resiter::{filter::*, flat_map::*, map::*}; -use std::error::Error; mod _foreign_impl; pub mod adapter; @@ -53,7 +53,7 @@ pub trait Graph { where Self: 'x; /// The error type that this graph may raise. - type Error: Error + 'static + Send + Sync; + type Error: Error + 'static; /// An iterator visiting all triples of this graph in arbitrary order. /// diff --git a/api/src/lib.rs b/api/src/lib.rs index 4cf3d65d..bed15ef0 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -66,3 +66,5 @@ pub mod triple; /// Re-export MownStr to avoid dependency version mismatch. /// pub use mownstr::MownStr; + +pub use sophia_iri::Error; diff --git a/api/src/source.rs b/api/src/source.rs index 22a78497..28c010a5 100644 --- a/api/src/source.rs +++ b/api/src/source.rs @@ -56,7 +56,7 @@ //! [`for_each_quad`]: QuadSource::for_each_quad //! [higher-rank trait bounds]: https://doc.rust-lang.org/nomicon/hrtb.html -use std::error::Error; +use crate::Error; pub mod convert; pub mod filter; @@ -87,7 +87,7 @@ pub trait Source { /// The type of items this source yields. type Item<'x>; /// The type of errors produced by this source. - type Error: Error + 'static + Send + Sync; + type Error: Error + 'static; /// Call f for some item(s) (possibly zero) from this source, if any. /// @@ -200,7 +200,7 @@ pub trait Source { impl<'a, I, T, E> Source for I where I: Iterator> + 'a, - E: Error + 'static + Send + Sync, + E: Error + 'static, { type Item<'x> = T; type Error = E; diff --git a/api/src/term.rs b/api/src/term.rs index d51e928d..75834ceb 100644 --- a/api/src/term.rs +++ b/api/src/term.rs @@ -575,7 +575,7 @@ pub trait FromTerm: Sized { /// See also [`FromTerm`] pub trait TryFromTerm: Sized { /// The error type produced when failing to copy a given term - type Error: 'static + std::error::Error + Send + Sync; + type Error: 'static + crate::Error; /// Try to copy `term` into an instance of this type. fn try_from_term(term: T) -> Result; } diff --git a/inmem/src/index.rs b/inmem/src/index.rs index 0f1df6ed..364cbd3a 100644 --- a/inmem/src/index.rs +++ b/inmem/src/index.rs @@ -1,8 +1,8 @@ //! A [`TermIndex`] is a bidirectional assocuation of [terms](Term) with short numeric [indices](Index). use sophia_api::term::{FromTerm, GraphName, SimpleTerm, Term}; +use sophia_api::Error; use std::collections::hash_map::Entry; use std::collections::HashMap; -use std::error::Error; /// Abstraction of the short numeric indices representing [terms](Term) in a [`TermIndex`]. pub trait Index: Copy + std::fmt::Debug + Ord { @@ -64,7 +64,7 @@ pub trait TermIndex { /// The type of [indices](Index) used by this [`TermIndex`] type Index: Index; /// The type of error that this [`TermIndex`] may raise - type Error: Error + 'static + Send + Sync; + type Error: Error + 'static; /// Get the index corresponding to term `t`, if it exists. /// @@ -195,7 +195,7 @@ mod test { use sophia_api::term::BnodeId; #[test] - fn simple_term_index() -> Result<(), Box> { + fn simple_term_index() -> Result<(), Box> { let ex = Namespace::new_unchecked("https://example.com/ns/"); let exa = ex.get("a")?; let exb = ex.get("b")?; diff --git a/iri/Cargo.toml b/iri/Cargo.toml index 3d8f1794..2b1ebe2b 100644 --- a/iri/Cargo.toml +++ b/iri/Cargo.toml @@ -27,6 +27,7 @@ criterion.workspace = true toml = "0.8.0" [features] +threadsafe_err = [] default = ["serde"] test_data = [] examples = [] diff --git a/iri/src/lib.rs b/iri/src/lib.rs index 23d5a5ef..f4b60071 100644 --- a/iri/src/lib.rs +++ b/iri/src/lib.rs @@ -40,3 +40,12 @@ pub mod wrap_macro_examples; #[cfg(any(test, feature = "test_data"))] pub mod test; + +#[cfg(not(feature = "threadsafe_err"))] +pub use std::error::Error; +#[cfg(feature = "threadsafe_err")] +pub use ThreadSafeError as Error; + +///! An error trait meant to enable sending errors safely across threads. +pub trait ThreadSafeError: std::error::Error + Send + Sync + 'static {} +impl ThreadSafeError for E where E: std::error::Error + Send + Sync + 'static {} diff --git a/resource/src/lib.rs b/resource/src/lib.rs index 3aff4c93..37aa28ce 100644 --- a/resource/src/lib.rs +++ b/resource/src/lib.rs @@ -20,7 +20,7 @@ mod test { use sophia_api::{ prelude::{Graph, Term}, term::SimpleTerm, - MownStr, + Error, MownStr, }; use sophia_iri::Iri; @@ -72,7 +72,7 @@ mod test { pub const F5_LEN: usize = 20; pub type MyGraph = Vec<[SimpleTerm<'static>; 3]>; - pub type TestResult = Result<(), Box>; + pub type TestResult = Result<(), Box>; pub fn make_loader() -> LocalLoader { let ns = NS.map_unchecked(MownStr::from); diff --git a/resource/src/resource/_error.rs b/resource/src/resource/_error.rs index 125786d5..d56b5833 100644 --- a/resource/src/resource/_error.rs +++ b/resource/src/resource/_error.rs @@ -1,11 +1,10 @@ use sophia_api::term::TermKind; -use sophia_api::{prelude::*, term::SimpleTerm}; -use std::error::Error; +use sophia_api::{prelude::*, term::SimpleTerm, Error}; use std::fmt; /// An error raised when creating a [`Resource`](crate::Resource) #[derive(Debug)] -pub enum ResourceError { +pub enum ResourceError { /// The IRI is not absolute (an can therefore not be dereferenced) IriNotAbsolute(IriRef>), /// The resource could not be loaded @@ -70,7 +69,7 @@ pub enum ResourceError { }, } -impl ResourceError +impl ResourceError where Self: Send + Sync + 'static, { @@ -94,19 +93,19 @@ where } } -impl fmt::Display for ResourceError { +impl fmt::Display for ResourceError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } } -impl From for ResourceError { +impl From for ResourceError { fn from(value: crate::loader::LoaderError) -> Self { Self::LoaderError(value) } } -impl Error for ResourceError where Self: Send + Sync + 'static {} +impl Error for ResourceError {} /// A result whose error is a [`ResourceError`] pub type ResourceResult = Result::Error>>; diff --git a/resource/src/resource/_struct.rs b/resource/src/resource/_struct.rs index fd2062ca..8d96927c 100644 --- a/resource/src/resource/_struct.rs +++ b/resource/src/resource/_struct.rs @@ -2,6 +2,7 @@ use crate::Loader; use sophia_api::graph::CollectibleGraph; use sophia_api::ns::rdf; use sophia_api::term::matcher::Any; +use sophia_api::Error; use sophia_api::MownStr; use sophia_api::{prelude::*, term::SimpleTerm}; use sophia_iri::is_absolute_iri_ref; @@ -22,7 +23,7 @@ pub struct Resource { impl Resource where G: Graph + 'static, - G::Error: Send + Sync + 'static, + // G::Error: Error, L: Loader, { /// Constructor diff --git a/resource/src/resource/test.rs b/resource/src/resource/test.rs index 467744ad..a573374d 100644 --- a/resource/src/resource/test.rs +++ b/resource/src/resource/test.rs @@ -597,8 +597,6 @@ fn no_reload() -> TestResult { Ok(()) } -fn make_rsc( - iri: Iri<&str>, -) -> Result, Box> { +fn make_rsc(iri: Iri<&str>) -> Result, Box> { Ok(make_loader().arced().get_resource(iri)?) } diff --git a/rio/src/parser.rs b/rio/src/parser.rs index 4282477c..e92d791d 100644 --- a/rio/src/parser.rs +++ b/rio/src/parser.rs @@ -8,7 +8,7 @@ use crate::model::Trusted; use sophia_api::source::{StreamError, StreamError::*, StreamResult}; -use std::error::Error; +use sophia_api::Error; /// Wrap a Rio [`TriplesParser`](rio_api::parser::TriplesParser) /// into a Sophia [`TripleSource`](sophia_api::source::TripleSource). @@ -17,7 +17,7 @@ pub struct StrictRioTripleSource(pub T); impl sophia_api::source::Source for StrictRioTripleSource where T: rio_api::parser::TriplesParser, - T::Error: Error + 'static + Send + Sync, + T::Error: Error + 'static, { type Item<'x> = Trusted>; @@ -50,7 +50,7 @@ pub struct StrictRioQuadSource(pub T); impl sophia_api::source::Source for StrictRioQuadSource where T: rio_api::parser::QuadsParser, - T::Error: Error + 'static + Send + Sync, + T::Error: Error + 'static, { type Item<'x> = Trusted>; @@ -83,7 +83,7 @@ pub struct GeneralizedRioSource(pub T); impl sophia_api::source::Source for GeneralizedRioSource where T: rio_api::parser::GeneralizedQuadsParser, - T::Error: Error + 'static + Send + Sync, + T::Error: Error + 'static, { type Item<'x> = Trusted>; From 6d9e1cd63e6d075c37ed5fad1b99bd5f6ce67dbc Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 13:01:29 -0500 Subject: [PATCH 07/20] revert imports --- inmem/src/index.rs | 2 +- resource/src/lib.rs | 4 ++-- resource/src/loader/_error.rs | 2 +- resource/src/resource/_error.rs | 5 +---- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/inmem/src/index.rs b/inmem/src/index.rs index 364cbd3a..75342db4 100644 --- a/inmem/src/index.rs +++ b/inmem/src/index.rs @@ -195,7 +195,7 @@ mod test { use sophia_api::term::BnodeId; #[test] - fn simple_term_index() -> Result<(), Box> { + fn simple_term_index() -> Result<(), Box> { let ex = Namespace::new_unchecked("https://example.com/ns/"); let exa = ex.get("a")?; let exb = ex.get("b")?; diff --git a/resource/src/lib.rs b/resource/src/lib.rs index 37aa28ce..b71ebb69 100644 --- a/resource/src/lib.rs +++ b/resource/src/lib.rs @@ -20,7 +20,7 @@ mod test { use sophia_api::{ prelude::{Graph, Term}, term::SimpleTerm, - Error, MownStr, + MownStr, }; use sophia_iri::Iri; @@ -72,7 +72,7 @@ mod test { pub const F5_LEN: usize = 20; pub type MyGraph = Vec<[SimpleTerm<'static>; 3]>; - pub type TestResult = Result<(), Box>; + pub type TestResult = Result<(), Box>; pub fn make_loader() -> LocalLoader { let ns = NS.map_unchecked(MownStr::from); diff --git a/resource/src/loader/_error.rs b/resource/src/loader/_error.rs index f33febd0..b877a05e 100644 --- a/resource/src/loader/_error.rs +++ b/resource/src/loader/_error.rs @@ -20,7 +20,7 @@ pub enum LoaderError { CantGuessSyntax(IriBuf), /// An error was encountered while parsing the data into an RDF graph #[error("Can not parse {0:?}: {1}")] - ParseError(IriBuf, Box), + ParseError(IriBuf, Box), } impl LoaderError { diff --git a/resource/src/resource/_error.rs b/resource/src/resource/_error.rs index d56b5833..cc67cb22 100644 --- a/resource/src/resource/_error.rs +++ b/resource/src/resource/_error.rs @@ -69,10 +69,7 @@ pub enum ResourceError { }, } -impl ResourceError -where - Self: Send + Sync + 'static, -{ +impl ResourceError { /// The identifier of the resource raising the error. /// /// NB: for errors raised during creation ([`ResourceError::IriNotAbsolute`], [`ResourceError::LoaderError`]), From 7220bf16bf8e8447ff3e77fd641e122e8be2afcd Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 13:11:32 -0500 Subject: [PATCH 08/20] macro refer --- api/src/dataset.rs | 8 ++--- api/src/dataset/test.rs | 62 ++++++++++++++++---------------- api/src/graph.rs | 8 ++--- api/src/graph/test.rs | 44 +++++++++++------------ api/src/serializer.rs | 4 +-- api/src/source/_stream_error.rs | 2 +- api/src/source/convert.rs | 4 +-- api/src/sparql.rs | 2 +- api/src/term/_native_literal.rs | 12 +++---- sophia/Cargo.toml | 1 + turtle/src/parser/gnq.rs | 2 +- turtle/src/parser/gtrig.rs | 2 +- turtle/src/parser/nq.rs | 2 +- turtle/src/parser/nt.rs | 2 +- turtle/src/parser/trig.rs | 2 +- turtle/src/parser/turtle.rs | 2 +- turtle/src/serializer/_pretty.rs | 2 +- turtle/src/serializer/nq.rs | 2 +- turtle/src/serializer/nt.rs | 2 +- turtle/src/serializer/trig.rs | 4 +-- turtle/src/serializer/turtle.rs | 4 +-- 21 files changed, 87 insertions(+), 86 deletions(-) diff --git a/api/src/dataset.rs b/api/src/dataset.rs index 8405c5c5..41218d59 100644 --- a/api/src/dataset.rs +++ b/api/src/dataset.rs @@ -69,7 +69,7 @@ pub trait Dataset { /// The result of this method is an iterator, /// so it can be used in a `for` loop: /// ``` - /// # fn test() -> Result<(), Box> { + /// # fn test() -> Result<(), Box> { /// # use sophia_api::dataset::Dataset; /// # use sophia_api::term::SimpleTerm; /// # let dataset = Vec::<[SimpleTerm;4]>::new(); @@ -88,7 +88,7 @@ pub trait Dataset { /// # use sophia_api::dataset::Dataset; /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::source::QuadSource; - /// # fn test() -> Result<(), Box> { + /// # fn test() -> Result<(), Box> { /// # let dataset = Vec::<[SimpleTerm;4]>::new(); /// # /// dataset.quads().for_each_quad(|q| { @@ -117,7 +117,7 @@ pub trait Dataset { /// # use sophia_api::prelude::*; /// # use sophia_api::ns::{Namespace, rdf}; /// # - /// # fn test(dataset: &G) -> Result<(), Box> + /// # fn test(dataset: &G) -> Result<(), Box> /// # where /// # G: Dataset, /// # { @@ -141,7 +141,7 @@ pub trait Dataset { /// # use sophia_api::quad::Quad; /// # use sophia_api::ns::rdfs; /// # - /// # fn test(dataset: &G) -> Result<(), Box> + /// # fn test(dataset: &G) -> Result<(), Box> /// # where /// # G: Dataset, /// # { diff --git a/api/src/dataset/test.rs b/api/src/dataset/test.rs index 16f32c53..d22ac157 100644 --- a/api/src/dataset/test.rs +++ b/api/src/dataset/test.rs @@ -157,7 +157,7 @@ macro_rules! test_dataset_impl { $crate::test_dataset_impl!($module_name, $dataset_impl, $is_set, $is_gen, $dataset_collector, { // these tests will only be performed for implementations of `MutableDataset` #[test] - fn simple_mutations() -> Result<(), Box> { + fn simple_mutations() -> Result<(), Box> { let mut d: $dataset_impl = $dataset_collector(no_quad()).unwrap(); assert_eq!(d.quads().count(), 0); assert!(MutableDataset::insert( @@ -196,7 +196,7 @@ macro_rules! test_dataset_impl { } #[test] - fn handle_duplicate() -> Result<(), Box> { + fn handle_duplicate() -> Result<(), Box> { let mut d: $dataset_impl = $dataset_collector(no_quad()).unwrap(); assert_eq!(d.quads().count(), 0); assert!(MutableDataset::insert( @@ -239,7 +239,7 @@ macro_rules! test_dataset_impl { } #[test] - fn different_graphs_do_not_count_as_duplicate() -> Result<(), Box> { + fn different_graphs_do_not_count_as_duplicate() -> Result<(), Box> { let mut d: $dataset_impl = $dataset_collector(no_quad()).unwrap(); assert_eq!(d.quads().count(), 0); assert!(MutableDataset::insert( @@ -304,7 +304,7 @@ macro_rules! test_dataset_impl { } #[test] - fn remove_matching() -> Result<(), Box> { + fn remove_matching() -> Result<(), Box> { let mut d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); d.remove_matching(Any, [rdf::type_], [*C1, *C2], Any)?; @@ -313,7 +313,7 @@ macro_rules! test_dataset_impl { } #[test] - fn retain_matching() -> Result<(), Box> { + fn retain_matching() -> Result<(), Box> { let mut d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); d.retain_matching(Any, [rdf::type_], [*C1, *C2], Any)?; @@ -337,7 +337,7 @@ macro_rules! test_dataset_impl { use super::*; #[test] - fn quads() -> Result<(), Box> { + fn quads() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); for iter in [Box::new(d.quads()) as Box>, Box::new(d.quads_matching(Any, Any, Any, Any))] { @@ -353,7 +353,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_s() -> Result<(), Box> { + fn quads_with_s() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C2], Any, Any, Any); @@ -380,7 +380,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_p() -> Result<(), Box> { + fn quads_with_p() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, [rdfs::subClassOf], Any, Any); @@ -401,7 +401,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_o() -> Result<(), Box> { + fn quads_with_o() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, Any, [*I2B], Any); @@ -416,7 +416,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_g() -> Result<(), Box> { + fn quads_with_g() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, Any, Any, [GN1.as_ref()]); @@ -431,7 +431,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_sp() -> Result<(), Box> { + fn quads_with_sp() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C2], [rdf::type_], Any, Any); @@ -452,7 +452,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_so() -> Result<(), Box> { + fn quads_with_so() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C2], Any, [*C1], Any); @@ -467,7 +467,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_po() -> Result<(), Box> { + fn quads_with_po() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, [rdf::type_], [rdfs::Class], Any); @@ -496,7 +496,7 @@ macro_rules! test_dataset_impl { #[test] - fn quads_with_sg() -> Result<(), Box> { + fn quads_with_sg() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C2], Any, Any, [GN1.as_ref()]); @@ -511,7 +511,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_pg() -> Result<(), Box> { + fn quads_with_pg() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, [rdf::type_], Any, [GN1.as_ref()]); @@ -526,7 +526,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_og() -> Result<(), Box> { + fn quads_with_og() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, Any, [*C1], [GN1.as_ref()]); @@ -541,7 +541,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_spo() -> Result<(), Box> { + fn quads_with_spo() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C1], [rdf::type_], [rdfs::Class], Any); @@ -556,7 +556,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_spg() -> Result<(), Box> { + fn quads_with_spg() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C1], [rdf::type_], Any, [DG.as_ref()]); @@ -577,7 +577,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_sog() -> Result<(), Box> { + fn quads_with_sog() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C1], Any, [rdfs::Class], [DG.as_ref()]); @@ -598,7 +598,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_pog() -> Result<(), Box> { + fn quads_with_pog() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, [rdf::type_], [rdfs::Class], [DG.as_ref()]); @@ -619,7 +619,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_spog() -> Result<(), Box> { + fn quads_with_spog() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C1], [rdf::type_], [rdfs::Class], [DG.as_ref()]); @@ -640,7 +640,7 @@ macro_rules! test_dataset_impl { } #[test] - fn contains() -> Result<(), Box> { + fn contains() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); assert!(Dataset::contains(&d, &*C2, &rdfs::subClassOf, &*C1, GN1.as_ref())?); assert!(!Dataset::contains(&d, &*C1, &rdfs::subClassOf, &*C2, GN1.as_ref())?); @@ -648,7 +648,7 @@ macro_rules! test_dataset_impl { } #[test] - fn subjects() -> Result<(), Box> { + fn subjects() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let subjects: HashSet = d.subjects().map(|t| t.unwrap().into_term()).collect(); @@ -675,7 +675,7 @@ macro_rules! test_dataset_impl { } #[test] - fn predicates() -> Result<(), Box> { + fn predicates() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let predicates: HashSet = d.predicates().map(|t| t.unwrap().into_term()).collect(); @@ -699,7 +699,7 @@ macro_rules! test_dataset_impl { } #[test] - fn objects() -> Result<(), Box> { + fn objects() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let objects: HashSet = d.objects().map(|t| t.unwrap().into_term()).collect(); @@ -726,7 +726,7 @@ macro_rules! test_dataset_impl { } #[test] - fn graph_names() -> Result<(), Box> { + fn graph_names() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let graph_names: HashSet = d.graph_names().map(|t| t.unwrap().into_term()).collect(); @@ -747,7 +747,7 @@ macro_rules! test_dataset_impl { } #[test] - fn iris() -> Result<(), Box> { + fn iris() -> Result<(), Box> { let d = if $is_gen { $dataset_collector(generalized_node_types_quads()).unwrap() } else { @@ -763,7 +763,7 @@ macro_rules! test_dataset_impl { } #[test] - fn bnodes() -> Result<(), Box> { + fn bnodes() -> Result<(), Box> { let d = if $is_gen { $dataset_collector(generalized_node_types_quads()).unwrap() } else { @@ -779,7 +779,7 @@ macro_rules! test_dataset_impl { } #[test] - fn literals() -> Result<(), Box> { + fn literals() -> Result<(), Box> { let d = if $is_gen { $dataset_collector(generalized_node_types_quads()).unwrap() } else { @@ -798,7 +798,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quoted_triples() -> Result<(), Box> { + fn quoted_triples() -> Result<(), Box> { if $is_gen { let d: $dataset_impl = $dataset_collector(generalized_node_types_quads()).unwrap(); @@ -844,7 +844,7 @@ macro_rules! test_dataset_impl { } #[test] - fn variables() -> Result<(), Box> { + fn variables() -> Result<(), Box> { if $is_gen { let d: $dataset_impl = $dataset_collector(generalized_node_types_quads()).unwrap(); diff --git a/api/src/graph.rs b/api/src/graph.rs index 83df2324..0168bfea 100644 --- a/api/src/graph.rs +++ b/api/src/graph.rs @@ -66,7 +66,7 @@ pub trait Graph { /// The result of this method is an iterator, /// so it can be used in a `for` loop: /// ``` - /// # fn test() -> Result<(), Box> { + /// # fn test() -> Result<(), Box> { /// # use sophia_api::graph::Graph; /// # use sophia_api::term::SimpleTerm; /// # let graph = Vec::<[SimpleTerm;3]>::new(); @@ -85,7 +85,7 @@ pub trait Graph { /// # use sophia_api::graph::Graph; /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::source::TripleSource; - /// # fn test() -> Result<(), Box> { + /// # fn test() -> Result<(), Box> { /// # let graph = Vec::<[SimpleTerm;3]>::new(); /// # /// graph.triples().for_each_triple(|t| { @@ -114,7 +114,7 @@ pub trait Graph { /// # use sophia_api::prelude::*; /// # use sophia_api::ns::{Namespace, rdf}; /// # - /// # fn test(graph: &G) -> Result<(), Box> + /// # fn test(graph: &G) -> Result<(), Box> /// # where /// # G: Graph, /// # { @@ -137,7 +137,7 @@ pub trait Graph { /// # use sophia_api::ns::rdfs; /// # use sophia_api::term::SimpleTerm; /// # - /// # fn test(graph: &G) -> Result<(), Box> + /// # fn test(graph: &G) -> Result<(), Box> /// # where /// # G: Graph, /// # { diff --git a/api/src/graph/test.rs b/api/src/graph/test.rs index dcde6d6e..4ae79b77 100644 --- a/api/src/graph/test.rs +++ b/api/src/graph/test.rs @@ -191,7 +191,7 @@ macro_rules! test_graph_impl { $crate::test_graph_impl!($module_name, $graph_impl, $is_set, $is_gen, $graph_collector, { // these tests will only be performed for implementations of `MutableGraph` #[test] - fn simple_mutations() -> Result<(), Box> { + fn simple_mutations() -> Result<(), Box> { let mut g: $graph_impl = $graph_collector(no_triple()).unwrap(); assert_eq!(g.triples().count(), 0); assert!(MutableGraph::insert( @@ -216,7 +216,7 @@ macro_rules! test_graph_impl { } #[test] - fn handle_duplicate() -> Result<(), Box> { + fn handle_duplicate() -> Result<(), Box> { let mut g: $graph_impl = $graph_collector(no_triple()).unwrap(); assert_eq!(g.triples().count(), 0); assert!(MutableGraph::insert( @@ -281,7 +281,7 @@ macro_rules! test_graph_impl { } #[test] - fn remove_matching() -> Result<(), Box> { + fn remove_matching() -> Result<(), Box> { let mut g: $graph_impl = $graph_collector(some_triples()).unwrap(); let o_matcher: &[_] = &[*C1, *C2]; @@ -291,7 +291,7 @@ macro_rules! test_graph_impl { } #[test] - fn retain_matching() -> Result<(), Box> { + fn retain_matching() -> Result<(), Box> { let mut g: $graph_impl = $graph_collector(some_triples()).unwrap(); let o_matcher: &[_] = &[*C1, *C2]; @@ -315,7 +315,7 @@ macro_rules! test_graph_impl { use super::*; #[test] - fn triples() -> Result<(), Box> { + fn triples() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); for iter in [Box::new(g.triples()) as Box>, Box::new(g.triples_matching(Any, Any, Any))] { @@ -330,7 +330,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_s() -> Result<(), Box> { + fn triples_with_s() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching([*C2], Any, Any); @@ -344,7 +344,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_p() -> Result<(), Box> { + fn triples_with_p() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching(Any, [rdf::type_], Any); @@ -363,7 +363,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_o() -> Result<(), Box> { + fn triples_with_o() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching(Any, Any, [*C2]); @@ -377,7 +377,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_sp() -> Result<(), Box> { + fn triples_with_sp() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching([*C2], [rdf::type_], Any); @@ -391,7 +391,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_so() -> Result<(), Box> { + fn triples_with_so() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching([*C2], Any, [rdfs::Resource]); @@ -410,7 +410,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_po() -> Result<(), Box> { + fn triples_with_po() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching(Any, [rdf::type_], [rdfs::Class]); @@ -424,7 +424,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_spo() -> Result<(), Box> { + fn triples_with_spo() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching([*C2], [rdf::type_], [rdfs::Resource]); @@ -443,7 +443,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_matching() -> Result<(), Box> { + fn triples_matching() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching([*C2, *P2], [rdf::type_, rdfs::domain], |t: SimpleTerm<'_>| !Term::eq(&t, rdfs::Class)); @@ -462,7 +462,7 @@ macro_rules! test_graph_impl { } #[test] - fn contains() -> Result<(), Box> { + fn contains() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); assert!(Graph::contains(&g, &*C2, &rdfs::subClassOf, &*C1)?); @@ -471,7 +471,7 @@ macro_rules! test_graph_impl { } #[test] - fn subjects() -> Result<(), Box> { + fn subjects() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let subjects: HashSet = g.subjects().map(|t| t.unwrap().into_term()).collect(); @@ -498,7 +498,7 @@ macro_rules! test_graph_impl { } #[test] - fn predicates() -> Result<(), Box> { + fn predicates() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let predicates: HashSet = g.predicates().map(|t| t.unwrap().into_term()).collect(); @@ -522,7 +522,7 @@ macro_rules! test_graph_impl { } #[test] - fn objects() -> Result<(), Box> { + fn objects() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let objects: HashSet = g.objects().map(|t| t.unwrap().into_term()).collect(); @@ -549,7 +549,7 @@ macro_rules! test_graph_impl { } #[test] - fn iris() -> Result<(), Box> { + fn iris() -> Result<(), Box> { let g = if $is_gen { $graph_collector(generalized_node_types_triples()).unwrap() } else { @@ -566,7 +566,7 @@ macro_rules! test_graph_impl { } #[test] - fn bnodes() -> Result<(), Box> { + fn bnodes() -> Result<(), Box> { let g = if $is_gen { $graph_collector(generalized_node_types_triples()).unwrap() } else { @@ -581,7 +581,7 @@ macro_rules! test_graph_impl { } #[test] - fn literals() -> Result<(), Box> { + fn literals() -> Result<(), Box> { let g = if $is_gen { $graph_collector(generalized_node_types_triples()).unwrap() } else { @@ -598,7 +598,7 @@ macro_rules! test_graph_impl { } #[test] - fn quoted_triples() -> Result<(), Box> { + fn quoted_triples() -> Result<(), Box> { if $is_gen { let g: $graph_impl = $graph_collector(generalized_node_types_triples()).unwrap(); @@ -638,7 +638,7 @@ macro_rules! test_graph_impl { } #[test] - fn variables() -> Result<(), Box> { + fn variables() -> Result<(), Box> { if $is_gen { let g: $graph_impl = $graph_collector(generalized_node_types_triples()).unwrap(); diff --git a/api/src/serializer.rs b/api/src/serializer.rs index 4b368f41..b79a909f 100644 --- a/api/src/serializer.rs +++ b/api/src/serializer.rs @@ -18,7 +18,7 @@ use crate::source::*; /// A triple serializer writes triples according to a given format. pub trait TripleSerializer { /// The error type that may be raised during serialization. - type Error: 'static + std::error::Error; + type Error: 'static + crate::Error; /// Serialize all triples from the given [`TripleSource`]. fn serialize_triples( @@ -47,7 +47,7 @@ pub trait TripleSerializer { /// A quad serializer writes quads according to a given format. pub trait QuadSerializer { /// The error type that may be raised during serialization. - type Error: 'static + std::error::Error; + type Error: 'static + crate::Error; /// Serialize all quads from the given [`QuadSource`]. fn serialize_quads( diff --git a/api/src/source/_stream_error.rs b/api/src/source/_stream_error.rs index 5550c4f0..9990a353 100644 --- a/api/src/source/_stream_error.rs +++ b/api/src/source/_stream_error.rs @@ -1,4 +1,4 @@ -use std::error::Error; +use crate::Error; /// A error that is raised by functions that move fallible `Source`s into /// fallible `Sinks`. diff --git a/api/src/source/convert.rs b/api/src/source/convert.rs index 90c9184e..85ddb29c 100644 --- a/api/src/source/convert.rs +++ b/api/src/source/convert.rs @@ -16,7 +16,7 @@ impl Source for ToQuads { fn try_for_some_item(&mut self, mut f: F) -> super::StreamResult where - E: std::error::Error, + E: crate::Error, F: FnMut(Self::Item<'_>) -> Result<(), E>, { self.0.try_for_some_triple(|t| { @@ -40,7 +40,7 @@ impl Source for ToTriples { fn try_for_some_item(&mut self, mut f: F) -> super::StreamResult where - E: std::error::Error, + E: crate::Error, F: FnMut(Self::Item<'_>) -> Result<(), E>, { self.0.try_for_some_quad(|q| { diff --git a/api/src/sparql.rs b/api/src/sparql.rs index a4d12916..48ea84ee 100644 --- a/api/src/sparql.rs +++ b/api/src/sparql.rs @@ -30,7 +30,7 @@ use crate::source::TripleSource; use crate::term::Term; use std::borrow::Borrow; -use std::error::Error; +use crate::Error; /// A dataset that can be queried with SPARQL. pub trait SparqlDataset { diff --git a/api/src/term/_native_literal.rs b/api/src/term/_native_literal.rs index 1b301cee..b33c3b0e 100644 --- a/api/src/term/_native_literal.rs +++ b/api/src/term/_native_literal.rs @@ -17,7 +17,7 @@ lazy_static::lazy_static! { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// graph.insert(&subject, &rdf::value, 3.14)?; @@ -53,7 +53,7 @@ impl Term for f64 { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// graph.insert(&subject, &rdf::value, 42)?; @@ -89,7 +89,7 @@ impl Term for i32 { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// let answer: isize = 42; @@ -126,7 +126,7 @@ impl Term for isize { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// let answer: usize = 42; @@ -163,7 +163,7 @@ impl Term for usize { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// graph.insert(&subject, &rdfs::label, "hello world")?; @@ -199,7 +199,7 @@ impl Term for str { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// graph.insert(&subject, &rdf::value, true)?; diff --git a/sophia/Cargo.toml b/sophia/Cargo.toml index 6a27f7d3..04ad39ae 100644 --- a/sophia/Cargo.toml +++ b/sophia/Cargo.toml @@ -25,6 +25,7 @@ test_macro = ["sophia_api/test_macro"] file_url = ["sophia_jsonld/file_url", "sophia_resource/file_url"] # This feature enables the HTTP client in dependencies http_client = ["sophia_jsonld/http_client", "sophia_resource/http_client"] +threadsafe_err = ["sophia_api/threadsafe_err"] [dependencies] sophia_iri.workspace = true diff --git a/turtle/src/parser/gnq.rs b/turtle/src/parser/gnq.rs index 442d2f77..56b14f9d 100644 --- a/turtle/src/parser/gnq.rs +++ b/turtle/src/parser/gnq.rs @@ -37,7 +37,7 @@ mod test { type MyDataset = Vec>>; #[test] - fn test_simple_gnq_string() -> std::result::Result<(), Box> { + fn test_simple_gnq_string() -> std::result::Result<(), Box> { let nq = r#" _:b1. _:b1 . diff --git a/turtle/src/parser/gtrig.rs b/turtle/src/parser/gtrig.rs index 5fce276c..dcb56036 100644 --- a/turtle/src/parser/gtrig.rs +++ b/turtle/src/parser/gtrig.rs @@ -46,7 +46,7 @@ mod test { type MyDataset = Vec>>; #[test] - fn test_simple_gtrig_string() -> std::result::Result<(), Box> { + fn test_simple_gtrig_string() -> std::result::Result<(), Box> { let gtrig = r#" @prefix : . diff --git a/turtle/src/parser/nq.rs b/turtle/src/parser/nq.rs index adac0bf3..32517a69 100644 --- a/turtle/src/parser/nq.rs +++ b/turtle/src/parser/nq.rs @@ -37,7 +37,7 @@ mod test { type MyDataset = Vec>>; #[test] - fn test_simple_nq_string() -> std::result::Result<(), Box> { + fn test_simple_nq_string() -> std::result::Result<(), Box> { let nq = r#" _:b1. _:b1 . diff --git a/turtle/src/parser/nt.rs b/turtle/src/parser/nt.rs index 825f26af..423ae63c 100644 --- a/turtle/src/parser/nt.rs +++ b/turtle/src/parser/nt.rs @@ -36,7 +36,7 @@ mod test { type MyGraph = Vec<[SimpleTerm<'static>; 3]>; #[test] - fn test_simple_nt_string() -> std::result::Result<(), Box> { + fn test_simple_nt_string() -> std::result::Result<(), Box> { let nt = r#" _:b1. _:b1 . diff --git a/turtle/src/parser/trig.rs b/turtle/src/parser/trig.rs index 6ef9ace5..66cca560 100644 --- a/turtle/src/parser/trig.rs +++ b/turtle/src/parser/trig.rs @@ -46,7 +46,7 @@ mod test { type MyDataset = Vec>>; #[test] - fn test_simple_trig_string() -> std::result::Result<(), Box> { + fn test_simple_trig_string() -> std::result::Result<(), Box> { let trig = r#" @prefix : . diff --git a/turtle/src/parser/turtle.rs b/turtle/src/parser/turtle.rs index a5531be2..43ee961a 100644 --- a/turtle/src/parser/turtle.rs +++ b/turtle/src/parser/turtle.rs @@ -43,7 +43,7 @@ mod test { type MyGraph = Vec<[SimpleTerm<'static>; 3]>; #[test] - fn test_simple_turtle_string() -> std::result::Result<(), Box> { + fn test_simple_turtle_string() -> std::result::Result<(), Box> { let turtle = r#" @prefix : . diff --git a/turtle/src/serializer/_pretty.rs b/turtle/src/serializer/_pretty.rs index b6ffe41a..8a38f318 100644 --- a/turtle/src/serializer/_pretty.rs +++ b/turtle/src/serializer/_pretty.rs @@ -792,7 +792,7 @@ pub(crate) mod test { } #[test] - fn relative_iri() -> Result<(), Box> { + fn relative_iri() -> Result<(), Box> { let iri = IriRef::new_unchecked(""); let graph = vec![[iri, iri, iri]]; let config = TurtleConfig::new().with_pretty(true); diff --git a/turtle/src/serializer/nq.rs b/turtle/src/serializer/nq.rs index 63c3eccb..a430f28a 100644 --- a/turtle/src/serializer/nq.rs +++ b/turtle/src/serializer/nq.rs @@ -115,7 +115,7 @@ pub(crate) mod test { use sophia_iri::Iri; #[test] - fn graph() -> Result<(), Box> { + fn graph() -> Result<(), Box> { let me = BnodeId::new_unchecked("me"); let mut d: Vec>> = vec![]; MutableDataset::insert( diff --git a/turtle/src/serializer/nt.rs b/turtle/src/serializer/nt.rs index 763b6b14..33a062a6 100644 --- a/turtle/src/serializer/nt.rs +++ b/turtle/src/serializer/nt.rs @@ -218,7 +218,7 @@ pub(crate) mod test { use sophia_iri::Iri; #[test] - fn graph() -> Result<(), Box> { + fn graph() -> Result<(), Box> { let me = BnodeId::new_unchecked("me"); let mut g: Vec<[SimpleTerm<'static>; 3]> = vec![]; MutableGraph::insert( diff --git a/turtle/src/serializer/trig.rs b/turtle/src/serializer/trig.rs index 921efd28..5bae06cc 100644 --- a/turtle/src/serializer/trig.rs +++ b/turtle/src/serializer/trig.rs @@ -111,7 +111,7 @@ pub(crate) mod test { use sophia_api::term::SimpleTerm; use sophia_api::{dataset::Dataset, quad::Spog}; use sophia_isomorphism::isomorphic_datasets; - use std::error::Error; + use sophia_api::Error; const TESTS: &[&str] = &[ "#empty trig", @@ -177,7 +177,7 @@ pub(crate) mod test { ]; #[test] - fn roundtrip_not_pretty() -> Result<(), Box> { + fn roundtrip_not_pretty() -> Result<(), Box> { for ttl in TESTS { println!("==========\n{}\n----------", ttl); let g1: Vec> = crate::parser::trig::parse_str(ttl).collect_quads()?; diff --git a/turtle/src/serializer/turtle.rs b/turtle/src/serializer/turtle.rs index cf944268..a2cc78ed 100644 --- a/turtle/src/serializer/turtle.rs +++ b/turtle/src/serializer/turtle.rs @@ -212,7 +212,7 @@ pub(crate) mod test { use super::*; use sophia_api::graph::Graph; use sophia_isomorphism::isomorphic_graphs; - use std::error::Error; + use sophia_api::Error; const TESTS: &[&str] = &[ "#empty ttl", @@ -246,7 +246,7 @@ pub(crate) mod test { ]; #[test] - fn roundtrip_not_pretty() -> Result<(), Box> { + fn roundtrip_not_pretty() -> Result<(), Box> { for ttl in TESTS { println!("==========\n{}\n----------", ttl); let g1: Vec<[SimpleTerm; 3]> = From 2a459e2479304e2e124fa2cf68f779f3537e41f1 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 13:20:43 -0500 Subject: [PATCH 09/20] further updates for error constraint --- book/src/ch01_getting_started.md | 2 +- book/src/ch02_rdf_terms.md | 8 ++++---- book/src/ch04_rdf_graphs.md | 10 +++++----- c14n/src/lib.rs | 2 +- c14n/src/rdfc10.rs | 2 +- isomorphism/src/test.rs | 2 +- jsonld/src/context.rs | 2 +- jsonld/src/parser/source.rs | 2 +- jsonld/src/serializer/test.rs | 2 +- resource/src/resource/_error.rs | 2 +- rio/src/serializer.rs | 2 ++ sophia/examples/canonicalize.rs | 2 +- sophia/examples/jsonld-context.rs | 4 ++-- xml/src/parser.rs | 2 +- xml/src/serializer.rs | 4 ++-- 15 files changed, 25 insertions(+), 23 deletions(-) diff --git a/book/src/ch01_getting_started.md b/book/src/ch01_getting_started.md index 67669eee..9a2524a4 100644 --- a/book/src/ch01_getting_started.md +++ b/book/src/ch01_getting_started.md @@ -41,7 +41,7 @@ graph.insert( let mut nt_stringifier = NtSerializer::new_stringifier(); let example2 = nt_stringifier.serialize_graph(&graph)?.as_str(); println!("The resulting graph:\n{}", example2); -# Ok::<(), Box>(()) +# Ok::<(), Box>(()) ``` You should get the following output: diff --git a/book/src/ch02_rdf_terms.md b/book/src/ch02_rdf_terms.md index 138e8fab..37c5ba00 100644 --- a/book/src/ch02_rdf_terms.md +++ b/book/src/ch02_rdf_terms.md @@ -78,7 +78,7 @@ More precisely, the type returned by [`t.borrow_term()`] is the associated type ### Constructing IRIs ```rust,noplayground -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # # use sophia::{iri::IriRef, api::ns::Namespace}; # let some_text = "http://example.org"; @@ -103,7 +103,7 @@ let iri6 = xsd::string ; ### Constructing literals ```rust,noplayground -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # # use sophia::api::{ns::xsd, term::{LanguageTag, SimpleTerm, Term}}; // use native types for xsd::string, xsd::integer, xsd::double @@ -123,7 +123,7 @@ let lit_date = "2023-11-15" * xsd::date; ### Constructing blank nodes ```rust,noplayground -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # # use sophia::api::term::BnodeId; let b = BnodeId::new_unchecked("x"); @@ -134,7 +134,7 @@ let b = BnodeId::new_unchecked("x"); ### Converting terms into a different type ```rust,noplayground # use sophia::api::{ns::xsd, term::{SimpleTerm, Term}}; -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # let some_term = "42" * xsd::integer; let t1: SimpleTerm = "hello".into_term(); let t2: i32 = some_term.try_into_term()?; diff --git a/book/src/ch04_rdf_graphs.md b/book/src/ch04_rdf_graphs.md index 6d399958..bc76524e 100644 --- a/book/src/ch04_rdf_graphs.md +++ b/book/src/ch04_rdf_graphs.md @@ -11,7 +11,7 @@ This is achieved with the [`Graph::triples`] method: ```rust,noplayground # use sophia::api::prelude::*; # use sophia::inmem::graph::LightGraph; -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # let g = LightGraph::new(); for result in g.triples() { let triple = result?; @@ -69,7 +69,7 @@ Inserting (resp. removing) a triple that is already (resp. not) present in the g ```rust,noplayground # use sophia::{api::{ns::rdf, prelude::*}, iri::*}; /// Example: increment the rdf:value of a given subject -# fn f(mut g: G) -> Result<(), Box> { +# fn f(mut g: G) -> Result<(), Box> { # let s = Iri::new_unchecked("https://example.org/foo"); let old_value: i32 = g.triples_matching([s], [rdf::value], Any) .next() @@ -109,7 +109,7 @@ and are described in more detail in the [next chapter](./ch05_term_matchers.md). ```rust,noplayground # use sophia::{api::{ns::{Namespace, rdf}, prelude::*}, inmem::graph::FastGraph}; -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { let mut g = FastGraph::new(); let ex = Namespace::new_unchecked("https://example.org/ns#"); let alice = ex.get_unchecked("alice"); @@ -131,7 +131,7 @@ g.insert( ```rust,noplayground # use sophia::{api::prelude::*, inmem::graph::FastGraph, iri::Iri}; -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # let big_graph = FastGraph::new(); // Extract all triples about 'alice' from big_graph in a new graph let alice = Iri::new_unchecked("https://example.org/ns#alice"); @@ -152,7 +152,7 @@ However, most types implementing [`Graph`] should implement [`CollectibleGraph`] # use std::{io::BufReader, fs::File}; use sophia::turtle::parser::turtle; -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { dbg!(std::env::current_dir()); let f = BufReader::new(File::open("../sophia_doap.ttl")?); let graph: FastGraph = turtle::parse_bufread(f) diff --git a/c14n/src/lib.rs b/c14n/src/lib.rs index acef4c25..ea553c66 100644 --- a/c14n/src/lib.rs +++ b/c14n/src/lib.rs @@ -26,7 +26,7 @@ use thiserror::Error; /// Canonicalization error. #[derive(Debug, Error)] -pub enum C14nError { +pub enum C14nError { /// The dataset raised an error during canonicalization #[error("Error from dataset: {0}")] Dataset(#[from] E), diff --git a/c14n/src/rdfc10.rs b/c14n/src/rdfc10.rs index 2195608b..e48453cb 100644 --- a/c14n/src/rdfc10.rs +++ b/c14n/src/rdfc10.rs @@ -302,7 +302,7 @@ impl<'a, H: HashFunction, T: Term> C14nState<'a, H, T> { } /// Implements https://www.w3.org/TR/rdf-canon/#hash-nd-quads - fn hash_n_degree_quads( + fn hash_n_degree_quads( &self, identifier: &str, issuer: &BnodeIssuer, diff --git a/isomorphism/src/test.rs b/isomorphism/src/test.rs index 8be3622c..de9de584 100644 --- a/isomorphism/src/test.rs +++ b/isomorphism/src/test.rs @@ -2,7 +2,7 @@ use super::*; use sophia_api::ns::xsd; use sophia_api::term::{assert_consistent_term_impl, BnodeId, IriRef, Term, TermKind}; use sophia_api::MownStr; -use std::error::Error; +use sophia_api::Error; const FOAF_KNOWS: MyTerm = MyTerm::Iri("http://xmlns.com/foaf/0.1/knows"); const FOAF_MBOX: MyTerm = MyTerm::Iri("http://xmlns.com/foaf/0.1/mbox"); diff --git a/jsonld/src/context.rs b/jsonld/src/context.rs index 917fd7ef..a657f2c0 100644 --- a/jsonld/src/context.rs +++ b/jsonld/src/context.rs @@ -43,7 +43,7 @@ pub trait TryIntoContextRef { } impl TryIntoContextRef for &str { - type Error = Box; + type Error = Box; fn try_into_context_ref(self) -> Result { let iri = ArcIri::new_unchecked("x-string://".into()); diff --git a/jsonld/src/parser/source.rs b/jsonld/src/parser/source.rs index 65908ee9..6dff84c6 100644 --- a/jsonld/src/parser/source.rs +++ b/jsonld/src/parser/source.rs @@ -33,7 +33,7 @@ impl Source for JsonLdQuadSource { fn try_for_some_item(&mut self, mut f: F) -> StreamResult where - E: std::error::Error, + E: sophia_api::Error, F: FnMut(Self::Item<'_>) -> Result<(), E>, { match self { diff --git a/jsonld/src/serializer/test.rs b/jsonld/src/serializer/test.rs index 96bc2dc2..edfe09ea 100644 --- a/jsonld/src/serializer/test.rs +++ b/jsonld/src/serializer/test.rs @@ -113,4 +113,4 @@ fn native_value() -> TestResult { Ok(()) } -pub type TestResult = Result<(), Box>; +pub type TestResult = Result<(), Box>; diff --git a/resource/src/resource/_error.rs b/resource/src/resource/_error.rs index cc67cb22..94cc63b8 100644 --- a/resource/src/resource/_error.rs +++ b/resource/src/resource/_error.rs @@ -102,7 +102,7 @@ impl From for ResourceError { } } -impl Error for ResourceError {} +impl std::error::Error for ResourceError {} /// A result whose error is a [`ResourceError`] pub type ResourceResult = Result::Error>>; diff --git a/rio/src/serializer.rs b/rio/src/serializer.rs index fb4b565d..c8cb1d95 100644 --- a/rio/src/serializer.rs +++ b/rio/src/serializer.rs @@ -21,6 +21,7 @@ pub fn rio_format_triples( ) -> StreamResult<(), TS::Error, TF::Error> where TF: TriplesFormatter, + TF::Error: sophia_api::Error, TS: TripleSource, { triples.try_for_each_triple(|t| { @@ -41,6 +42,7 @@ pub fn rio_format_quads( ) -> StreamResult<(), QS::Error, QF::Error> where QF: QuadsFormatter, + QF::Error: sophia_api::Error, QS: QuadSource, { quads.try_for_each_quad(|q| { diff --git a/sophia/examples/canonicalize.rs b/sophia/examples/canonicalize.rs index 5885d1dc..13454710 100644 --- a/sophia/examples/canonicalize.rs +++ b/sophia/examples/canonicalize.rs @@ -20,7 +20,7 @@ use sophia::turtle::parser::nq; use sophia_c14n::hash::Sha256; use sophia_c14n::rdfc10::{DEFAULT_DEPTH_FACTOR, DEFAULT_PERMUTATION_LIMIT}; -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { let input = BufReader::new(stdin()); let dataset: MyDataset = nq::parse_bufread(input).collect_quads()?; let output = BufWriter::new(stdout()); diff --git a/sophia/examples/jsonld-context.rs b/sophia/examples/jsonld-context.rs index a01f5aa8..efd8dcf5 100644 --- a/sophia/examples/jsonld-context.rs +++ b/sophia/examples/jsonld-context.rs @@ -14,7 +14,7 @@ use sophia::{ turtle::serializer::trig::{TrigConfig, TrigSerializer}, }; -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { let mut args = std::env::args(); let json_ld_path = args.nth(1).expect("Missing jsonld file."); let context_path = args.next(); @@ -42,7 +42,7 @@ fn main() -> Result<(), Box> { Ok(()) } -fn to_trig(quads: impl QuadSource) -> Result> { +fn to_trig(quads: impl QuadSource) -> Result> { let mut stringifier = TrigSerializer::new_stringifier_with_config(TrigConfig::new().with_pretty(true)); stringifier.serialize_quads(quads)?; diff --git a/xml/src/parser.rs b/xml/src/parser.rs index e550bd1e..6816ae63 100644 --- a/xml/src/parser.rs +++ b/xml/src/parser.rs @@ -46,7 +46,7 @@ mod test { type MyGraph = Vec<[SimpleTerm<'static>; 3]>; #[test] - fn test_simple_xml_string() -> std::result::Result<(), Box> { + fn test_simple_xml_string() -> std::result::Result<(), Box> { let xml = r#" diff --git a/xml/src/serializer.rs b/xml/src/serializer.rs index ec4f42f1..ddde6d2f 100644 --- a/xml/src/serializer.rs +++ b/xml/src/serializer.rs @@ -138,7 +138,7 @@ pub(crate) mod test { "#]; #[test] - fn roundtrip() -> Result<(), Box> { + fn roundtrip() -> Result<(), Box> { for rdfxml in TESTS { println!("==========\n{}\n----------", rdfxml); let g1: Vec<[SimpleTerm; 3]> = crate::parser::parse_str(rdfxml).collect_triples()?; @@ -156,7 +156,7 @@ pub(crate) mod test { } #[test] - fn roundtrip_with_ident() -> Result<(), Box> { + fn roundtrip_with_ident() -> Result<(), Box> { let config = RdfXmlConfig::new().with_indentation(4); for rdfxml in TESTS { println!("==========\n{}\n----------", rdfxml); From a69cdae8c82c05369b56ea5ca6892822bb289f80 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 13:26:47 -0500 Subject: [PATCH 10/20] last if dyn Error --- iri/src/lib.rs | 5 ++++- jsonld/src/context.rs | 2 +- resource/src/resource/_struct.rs | 2 -- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/iri/src/lib.rs b/iri/src/lib.rs index f4b60071..f6f19797 100644 --- a/iri/src/lib.rs +++ b/iri/src/lib.rs @@ -47,5 +47,8 @@ pub use std::error::Error; pub use ThreadSafeError as Error; ///! An error trait meant to enable sending errors safely across threads. -pub trait ThreadSafeError: std::error::Error + Send + Sync + 'static {} +pub trait ThreadSafeError: + core::fmt::Debug + core::fmt::Display + std::error::Error + Send + Sync + 'static +{ +} impl ThreadSafeError for E where E: std::error::Error + Send + Sync + 'static {} diff --git a/jsonld/src/context.rs b/jsonld/src/context.rs index a657f2c0..917fd7ef 100644 --- a/jsonld/src/context.rs +++ b/jsonld/src/context.rs @@ -43,7 +43,7 @@ pub trait TryIntoContextRef { } impl TryIntoContextRef for &str { - type Error = Box; + type Error = Box; fn try_into_context_ref(self) -> Result { let iri = ArcIri::new_unchecked("x-string://".into()); diff --git a/resource/src/resource/_struct.rs b/resource/src/resource/_struct.rs index 8d96927c..5860800f 100644 --- a/resource/src/resource/_struct.rs +++ b/resource/src/resource/_struct.rs @@ -2,7 +2,6 @@ use crate::Loader; use sophia_api::graph::CollectibleGraph; use sophia_api::ns::rdf; use sophia_api::term::matcher::Any; -use sophia_api::Error; use sophia_api::MownStr; use sophia_api::{prelude::*, term::SimpleTerm}; use sophia_iri::is_absolute_iri_ref; @@ -23,7 +22,6 @@ pub struct Resource { impl Resource where G: Graph + 'static, - // G::Error: Error, L: Loader, { /// Constructor From 5ad320ebbd8ca993055fb966b2bbfed753ecb1ae Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 13:28:43 -0500 Subject: [PATCH 11/20] revert some dochanges --- api/src/dataset.rs | 8 ++++---- iri/src/lib.rs | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/api/src/dataset.rs b/api/src/dataset.rs index 41218d59..b50293d5 100644 --- a/api/src/dataset.rs +++ b/api/src/dataset.rs @@ -69,7 +69,7 @@ pub trait Dataset { /// The result of this method is an iterator, /// so it can be used in a `for` loop: /// ``` - /// # fn test() -> Result<(), Box> { + /// # fn test() -> Result<(), Box> { /// # use sophia_api::dataset::Dataset; /// # use sophia_api::term::SimpleTerm; /// # let dataset = Vec::<[SimpleTerm;4]>::new(); @@ -88,7 +88,7 @@ pub trait Dataset { /// # use sophia_api::dataset::Dataset; /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::source::QuadSource; - /// # fn test() -> Result<(), Box> { + /// # fn test() -> Result<(), Box> { /// # let dataset = Vec::<[SimpleTerm;4]>::new(); /// # /// dataset.quads().for_each_quad(|q| { @@ -117,7 +117,7 @@ pub trait Dataset { /// # use sophia_api::prelude::*; /// # use sophia_api::ns::{Namespace, rdf}; /// # - /// # fn test(dataset: &G) -> Result<(), Box> + /// # fn test(dataset: &G) -> Result<(), Box> /// # where /// # G: Dataset, /// # { @@ -141,7 +141,7 @@ pub trait Dataset { /// # use sophia_api::quad::Quad; /// # use sophia_api::ns::rdfs; /// # - /// # fn test(dataset: &G) -> Result<(), Box> + /// # fn test(dataset: &G) -> Result<(), Box> /// # where /// # G: Dataset, /// # { diff --git a/iri/src/lib.rs b/iri/src/lib.rs index f6f19797..f4b60071 100644 --- a/iri/src/lib.rs +++ b/iri/src/lib.rs @@ -47,8 +47,5 @@ pub use std::error::Error; pub use ThreadSafeError as Error; ///! An error trait meant to enable sending errors safely across threads. -pub trait ThreadSafeError: - core::fmt::Debug + core::fmt::Display + std::error::Error + Send + Sync + 'static -{ -} +pub trait ThreadSafeError: std::error::Error + Send + Sync + 'static {} impl ThreadSafeError for E where E: std::error::Error + Send + Sync + 'static {} From b159d17cef5a7f6f0c9c41f4fc0e8e01582e1807 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 13:30:31 -0500 Subject: [PATCH 12/20] clippy --- api/src/sparql.rs | 2 +- api/src/term/_simple.rs | 2 +- iri/src/lib.rs | 2 +- isomorphism/src/test.rs | 2 +- turtle/src/serializer/trig.rs | 2 +- turtle/src/serializer/turtle.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/src/sparql.rs b/api/src/sparql.rs index 48ea84ee..f48b441b 100644 --- a/api/src/sparql.rs +++ b/api/src/sparql.rs @@ -29,8 +29,8 @@ use crate::source::TripleSource; use crate::term::Term; -use std::borrow::Borrow; use crate::Error; +use std::borrow::Borrow; /// A dataset that can be queried with SPARQL. pub trait SparqlDataset { diff --git a/api/src/term/_simple.rs b/api/src/term/_simple.rs index aa555bab..eae7034d 100644 --- a/api/src/term/_simple.rs +++ b/api/src/term/_simple.rs @@ -102,7 +102,7 @@ fn ensure_owned(m: MownStr) -> MownStr<'static> { let m = m.clone(); // Safety: the transmute bellow is safe, because if m.is_owned() is true, // then it's data is not restricted to lifetime 'a. - unsafe { std::mem::transmute(m) } + unsafe { std::mem::transmute::, mownstr::MownStr<'_>>(m) } } else { m.to_string().into() } diff --git a/iri/src/lib.rs b/iri/src/lib.rs index f4b60071..1c81ed89 100644 --- a/iri/src/lib.rs +++ b/iri/src/lib.rs @@ -46,6 +46,6 @@ pub use std::error::Error; #[cfg(feature = "threadsafe_err")] pub use ThreadSafeError as Error; -///! An error trait meant to enable sending errors safely across threads. +/// An error trait meant to enable sending errors safely across threads. pub trait ThreadSafeError: std::error::Error + Send + Sync + 'static {} impl ThreadSafeError for E where E: std::error::Error + Send + Sync + 'static {} diff --git a/isomorphism/src/test.rs b/isomorphism/src/test.rs index de9de584..a0c56b4b 100644 --- a/isomorphism/src/test.rs +++ b/isomorphism/src/test.rs @@ -1,8 +1,8 @@ use super::*; use sophia_api::ns::xsd; use sophia_api::term::{assert_consistent_term_impl, BnodeId, IriRef, Term, TermKind}; -use sophia_api::MownStr; use sophia_api::Error; +use sophia_api::MownStr; const FOAF_KNOWS: MyTerm = MyTerm::Iri("http://xmlns.com/foaf/0.1/knows"); const FOAF_MBOX: MyTerm = MyTerm::Iri("http://xmlns.com/foaf/0.1/mbox"); diff --git a/turtle/src/serializer/trig.rs b/turtle/src/serializer/trig.rs index 5bae06cc..63a1c7d2 100644 --- a/turtle/src/serializer/trig.rs +++ b/turtle/src/serializer/trig.rs @@ -109,9 +109,9 @@ impl Stringifier for TrigSerializer> { pub(crate) mod test { use super::*; use sophia_api::term::SimpleTerm; + use sophia_api::Error; use sophia_api::{dataset::Dataset, quad::Spog}; use sophia_isomorphism::isomorphic_datasets; - use sophia_api::Error; const TESTS: &[&str] = &[ "#empty trig", diff --git a/turtle/src/serializer/turtle.rs b/turtle/src/serializer/turtle.rs index a2cc78ed..92acc0f6 100644 --- a/turtle/src/serializer/turtle.rs +++ b/turtle/src/serializer/turtle.rs @@ -211,8 +211,8 @@ impl Stringifier for TurtleSerializer> { pub(crate) mod test { use super::*; use sophia_api::graph::Graph; - use sophia_isomorphism::isomorphic_graphs; use sophia_api::Error; + use sophia_isomorphism::isomorphic_graphs; const TESTS: &[&str] = &[ "#empty ttl", From 5a741f390896a74ff502146911db7ce526b4a1ca Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 13:57:06 -0500 Subject: [PATCH 13/20] rever dyn decls --- api/src/dataset.rs | 8 ++-- api/src/dataset/test.rs | 62 +++++++++++++++---------------- api/src/graph.rs | 8 ++-- api/src/graph/test.rs | 44 +++++++++++----------- api/src/term/_native_literal.rs | 12 +++--- book/src/ch01_getting_started.md | 2 +- book/src/ch02_rdf_terms.md | 8 ++-- book/src/ch04_rdf_graphs.md | 10 ++--- inmem/src/index.rs | 2 +- iri/src/lib.rs | 3 +- isomorphism/src/test.rs | 25 ++++++------- jsonld/src/serializer/test.rs | 2 +- resource/src/lib.rs | 2 +- resource/src/loader/_error.rs | 2 +- resource/src/resource/test.rs | 2 +- sophia/examples/canonicalize.rs | 2 +- sophia/examples/jsonld-context.rs | 4 +- turtle/src/parser/gnq.rs | 2 +- turtle/src/parser/gtrig.rs | 2 +- turtle/src/parser/nq.rs | 2 +- turtle/src/parser/nt.rs | 2 +- turtle/src/parser/trig.rs | 2 +- turtle/src/parser/turtle.rs | 2 +- turtle/src/serializer/_pretty.rs | 2 +- turtle/src/serializer/nq.rs | 2 +- turtle/src/serializer/nt.rs | 2 +- turtle/src/serializer/trig.rs | 4 +- turtle/src/serializer/turtle.rs | 5 +-- xml/src/parser.rs | 2 +- xml/src/serializer.rs | 4 +- 30 files changed, 115 insertions(+), 116 deletions(-) diff --git a/api/src/dataset.rs b/api/src/dataset.rs index b50293d5..8405c5c5 100644 --- a/api/src/dataset.rs +++ b/api/src/dataset.rs @@ -69,7 +69,7 @@ pub trait Dataset { /// The result of this method is an iterator, /// so it can be used in a `for` loop: /// ``` - /// # fn test() -> Result<(), Box> { + /// # fn test() -> Result<(), Box> { /// # use sophia_api::dataset::Dataset; /// # use sophia_api::term::SimpleTerm; /// # let dataset = Vec::<[SimpleTerm;4]>::new(); @@ -88,7 +88,7 @@ pub trait Dataset { /// # use sophia_api::dataset::Dataset; /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::source::QuadSource; - /// # fn test() -> Result<(), Box> { + /// # fn test() -> Result<(), Box> { /// # let dataset = Vec::<[SimpleTerm;4]>::new(); /// # /// dataset.quads().for_each_quad(|q| { @@ -117,7 +117,7 @@ pub trait Dataset { /// # use sophia_api::prelude::*; /// # use sophia_api::ns::{Namespace, rdf}; /// # - /// # fn test(dataset: &G) -> Result<(), Box> + /// # fn test(dataset: &G) -> Result<(), Box> /// # where /// # G: Dataset, /// # { @@ -141,7 +141,7 @@ pub trait Dataset { /// # use sophia_api::quad::Quad; /// # use sophia_api::ns::rdfs; /// # - /// # fn test(dataset: &G) -> Result<(), Box> + /// # fn test(dataset: &G) -> Result<(), Box> /// # where /// # G: Dataset, /// # { diff --git a/api/src/dataset/test.rs b/api/src/dataset/test.rs index d22ac157..16f32c53 100644 --- a/api/src/dataset/test.rs +++ b/api/src/dataset/test.rs @@ -157,7 +157,7 @@ macro_rules! test_dataset_impl { $crate::test_dataset_impl!($module_name, $dataset_impl, $is_set, $is_gen, $dataset_collector, { // these tests will only be performed for implementations of `MutableDataset` #[test] - fn simple_mutations() -> Result<(), Box> { + fn simple_mutations() -> Result<(), Box> { let mut d: $dataset_impl = $dataset_collector(no_quad()).unwrap(); assert_eq!(d.quads().count(), 0); assert!(MutableDataset::insert( @@ -196,7 +196,7 @@ macro_rules! test_dataset_impl { } #[test] - fn handle_duplicate() -> Result<(), Box> { + fn handle_duplicate() -> Result<(), Box> { let mut d: $dataset_impl = $dataset_collector(no_quad()).unwrap(); assert_eq!(d.quads().count(), 0); assert!(MutableDataset::insert( @@ -239,7 +239,7 @@ macro_rules! test_dataset_impl { } #[test] - fn different_graphs_do_not_count_as_duplicate() -> Result<(), Box> { + fn different_graphs_do_not_count_as_duplicate() -> Result<(), Box> { let mut d: $dataset_impl = $dataset_collector(no_quad()).unwrap(); assert_eq!(d.quads().count(), 0); assert!(MutableDataset::insert( @@ -304,7 +304,7 @@ macro_rules! test_dataset_impl { } #[test] - fn remove_matching() -> Result<(), Box> { + fn remove_matching() -> Result<(), Box> { let mut d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); d.remove_matching(Any, [rdf::type_], [*C1, *C2], Any)?; @@ -313,7 +313,7 @@ macro_rules! test_dataset_impl { } #[test] - fn retain_matching() -> Result<(), Box> { + fn retain_matching() -> Result<(), Box> { let mut d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); d.retain_matching(Any, [rdf::type_], [*C1, *C2], Any)?; @@ -337,7 +337,7 @@ macro_rules! test_dataset_impl { use super::*; #[test] - fn quads() -> Result<(), Box> { + fn quads() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); for iter in [Box::new(d.quads()) as Box>, Box::new(d.quads_matching(Any, Any, Any, Any))] { @@ -353,7 +353,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_s() -> Result<(), Box> { + fn quads_with_s() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C2], Any, Any, Any); @@ -380,7 +380,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_p() -> Result<(), Box> { + fn quads_with_p() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, [rdfs::subClassOf], Any, Any); @@ -401,7 +401,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_o() -> Result<(), Box> { + fn quads_with_o() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, Any, [*I2B], Any); @@ -416,7 +416,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_g() -> Result<(), Box> { + fn quads_with_g() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, Any, Any, [GN1.as_ref()]); @@ -431,7 +431,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_sp() -> Result<(), Box> { + fn quads_with_sp() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C2], [rdf::type_], Any, Any); @@ -452,7 +452,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_so() -> Result<(), Box> { + fn quads_with_so() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C2], Any, [*C1], Any); @@ -467,7 +467,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_po() -> Result<(), Box> { + fn quads_with_po() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, [rdf::type_], [rdfs::Class], Any); @@ -496,7 +496,7 @@ macro_rules! test_dataset_impl { #[test] - fn quads_with_sg() -> Result<(), Box> { + fn quads_with_sg() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C2], Any, Any, [GN1.as_ref()]); @@ -511,7 +511,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_pg() -> Result<(), Box> { + fn quads_with_pg() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, [rdf::type_], Any, [GN1.as_ref()]); @@ -526,7 +526,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_og() -> Result<(), Box> { + fn quads_with_og() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, Any, [*C1], [GN1.as_ref()]); @@ -541,7 +541,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_spo() -> Result<(), Box> { + fn quads_with_spo() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C1], [rdf::type_], [rdfs::Class], Any); @@ -556,7 +556,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_spg() -> Result<(), Box> { + fn quads_with_spg() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C1], [rdf::type_], Any, [DG.as_ref()]); @@ -577,7 +577,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_sog() -> Result<(), Box> { + fn quads_with_sog() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C1], Any, [rdfs::Class], [DG.as_ref()]); @@ -598,7 +598,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_pog() -> Result<(), Box> { + fn quads_with_pog() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching(Any, [rdf::type_], [rdfs::Class], [DG.as_ref()]); @@ -619,7 +619,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quads_with_spog() -> Result<(), Box> { + fn quads_with_spog() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let iter = d.quads_matching([*C1], [rdf::type_], [rdfs::Class], [DG.as_ref()]); @@ -640,7 +640,7 @@ macro_rules! test_dataset_impl { } #[test] - fn contains() -> Result<(), Box> { + fn contains() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); assert!(Dataset::contains(&d, &*C2, &rdfs::subClassOf, &*C1, GN1.as_ref())?); assert!(!Dataset::contains(&d, &*C1, &rdfs::subClassOf, &*C2, GN1.as_ref())?); @@ -648,7 +648,7 @@ macro_rules! test_dataset_impl { } #[test] - fn subjects() -> Result<(), Box> { + fn subjects() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let subjects: HashSet = d.subjects().map(|t| t.unwrap().into_term()).collect(); @@ -675,7 +675,7 @@ macro_rules! test_dataset_impl { } #[test] - fn predicates() -> Result<(), Box> { + fn predicates() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let predicates: HashSet = d.predicates().map(|t| t.unwrap().into_term()).collect(); @@ -699,7 +699,7 @@ macro_rules! test_dataset_impl { } #[test] - fn objects() -> Result<(), Box> { + fn objects() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let objects: HashSet = d.objects().map(|t| t.unwrap().into_term()).collect(); @@ -726,7 +726,7 @@ macro_rules! test_dataset_impl { } #[test] - fn graph_names() -> Result<(), Box> { + fn graph_names() -> Result<(), Box> { let d: $dataset_impl = $dataset_collector(some_quads()).unwrap(); let graph_names: HashSet = d.graph_names().map(|t| t.unwrap().into_term()).collect(); @@ -747,7 +747,7 @@ macro_rules! test_dataset_impl { } #[test] - fn iris() -> Result<(), Box> { + fn iris() -> Result<(), Box> { let d = if $is_gen { $dataset_collector(generalized_node_types_quads()).unwrap() } else { @@ -763,7 +763,7 @@ macro_rules! test_dataset_impl { } #[test] - fn bnodes() -> Result<(), Box> { + fn bnodes() -> Result<(), Box> { let d = if $is_gen { $dataset_collector(generalized_node_types_quads()).unwrap() } else { @@ -779,7 +779,7 @@ macro_rules! test_dataset_impl { } #[test] - fn literals() -> Result<(), Box> { + fn literals() -> Result<(), Box> { let d = if $is_gen { $dataset_collector(generalized_node_types_quads()).unwrap() } else { @@ -798,7 +798,7 @@ macro_rules! test_dataset_impl { } #[test] - fn quoted_triples() -> Result<(), Box> { + fn quoted_triples() -> Result<(), Box> { if $is_gen { let d: $dataset_impl = $dataset_collector(generalized_node_types_quads()).unwrap(); @@ -844,7 +844,7 @@ macro_rules! test_dataset_impl { } #[test] - fn variables() -> Result<(), Box> { + fn variables() -> Result<(), Box> { if $is_gen { let d: $dataset_impl = $dataset_collector(generalized_node_types_quads()).unwrap(); diff --git a/api/src/graph.rs b/api/src/graph.rs index 0168bfea..83df2324 100644 --- a/api/src/graph.rs +++ b/api/src/graph.rs @@ -66,7 +66,7 @@ pub trait Graph { /// The result of this method is an iterator, /// so it can be used in a `for` loop: /// ``` - /// # fn test() -> Result<(), Box> { + /// # fn test() -> Result<(), Box> { /// # use sophia_api::graph::Graph; /// # use sophia_api::term::SimpleTerm; /// # let graph = Vec::<[SimpleTerm;3]>::new(); @@ -85,7 +85,7 @@ pub trait Graph { /// # use sophia_api::graph::Graph; /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::source::TripleSource; - /// # fn test() -> Result<(), Box> { + /// # fn test() -> Result<(), Box> { /// # let graph = Vec::<[SimpleTerm;3]>::new(); /// # /// graph.triples().for_each_triple(|t| { @@ -114,7 +114,7 @@ pub trait Graph { /// # use sophia_api::prelude::*; /// # use sophia_api::ns::{Namespace, rdf}; /// # - /// # fn test(graph: &G) -> Result<(), Box> + /// # fn test(graph: &G) -> Result<(), Box> /// # where /// # G: Graph, /// # { @@ -137,7 +137,7 @@ pub trait Graph { /// # use sophia_api::ns::rdfs; /// # use sophia_api::term::SimpleTerm; /// # - /// # fn test(graph: &G) -> Result<(), Box> + /// # fn test(graph: &G) -> Result<(), Box> /// # where /// # G: Graph, /// # { diff --git a/api/src/graph/test.rs b/api/src/graph/test.rs index 4ae79b77..dcde6d6e 100644 --- a/api/src/graph/test.rs +++ b/api/src/graph/test.rs @@ -191,7 +191,7 @@ macro_rules! test_graph_impl { $crate::test_graph_impl!($module_name, $graph_impl, $is_set, $is_gen, $graph_collector, { // these tests will only be performed for implementations of `MutableGraph` #[test] - fn simple_mutations() -> Result<(), Box> { + fn simple_mutations() -> Result<(), Box> { let mut g: $graph_impl = $graph_collector(no_triple()).unwrap(); assert_eq!(g.triples().count(), 0); assert!(MutableGraph::insert( @@ -216,7 +216,7 @@ macro_rules! test_graph_impl { } #[test] - fn handle_duplicate() -> Result<(), Box> { + fn handle_duplicate() -> Result<(), Box> { let mut g: $graph_impl = $graph_collector(no_triple()).unwrap(); assert_eq!(g.triples().count(), 0); assert!(MutableGraph::insert( @@ -281,7 +281,7 @@ macro_rules! test_graph_impl { } #[test] - fn remove_matching() -> Result<(), Box> { + fn remove_matching() -> Result<(), Box> { let mut g: $graph_impl = $graph_collector(some_triples()).unwrap(); let o_matcher: &[_] = &[*C1, *C2]; @@ -291,7 +291,7 @@ macro_rules! test_graph_impl { } #[test] - fn retain_matching() -> Result<(), Box> { + fn retain_matching() -> Result<(), Box> { let mut g: $graph_impl = $graph_collector(some_triples()).unwrap(); let o_matcher: &[_] = &[*C1, *C2]; @@ -315,7 +315,7 @@ macro_rules! test_graph_impl { use super::*; #[test] - fn triples() -> Result<(), Box> { + fn triples() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); for iter in [Box::new(g.triples()) as Box>, Box::new(g.triples_matching(Any, Any, Any))] { @@ -330,7 +330,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_s() -> Result<(), Box> { + fn triples_with_s() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching([*C2], Any, Any); @@ -344,7 +344,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_p() -> Result<(), Box> { + fn triples_with_p() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching(Any, [rdf::type_], Any); @@ -363,7 +363,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_o() -> Result<(), Box> { + fn triples_with_o() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching(Any, Any, [*C2]); @@ -377,7 +377,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_sp() -> Result<(), Box> { + fn triples_with_sp() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching([*C2], [rdf::type_], Any); @@ -391,7 +391,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_so() -> Result<(), Box> { + fn triples_with_so() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching([*C2], Any, [rdfs::Resource]); @@ -410,7 +410,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_po() -> Result<(), Box> { + fn triples_with_po() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching(Any, [rdf::type_], [rdfs::Class]); @@ -424,7 +424,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_with_spo() -> Result<(), Box> { + fn triples_with_spo() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching([*C2], [rdf::type_], [rdfs::Resource]); @@ -443,7 +443,7 @@ macro_rules! test_graph_impl { } #[test] - fn triples_matching() -> Result<(), Box> { + fn triples_matching() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let iter = g.triples_matching([*C2, *P2], [rdf::type_, rdfs::domain], |t: SimpleTerm<'_>| !Term::eq(&t, rdfs::Class)); @@ -462,7 +462,7 @@ macro_rules! test_graph_impl { } #[test] - fn contains() -> Result<(), Box> { + fn contains() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); assert!(Graph::contains(&g, &*C2, &rdfs::subClassOf, &*C1)?); @@ -471,7 +471,7 @@ macro_rules! test_graph_impl { } #[test] - fn subjects() -> Result<(), Box> { + fn subjects() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let subjects: HashSet = g.subjects().map(|t| t.unwrap().into_term()).collect(); @@ -498,7 +498,7 @@ macro_rules! test_graph_impl { } #[test] - fn predicates() -> Result<(), Box> { + fn predicates() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let predicates: HashSet = g.predicates().map(|t| t.unwrap().into_term()).collect(); @@ -522,7 +522,7 @@ macro_rules! test_graph_impl { } #[test] - fn objects() -> Result<(), Box> { + fn objects() -> Result<(), Box> { let g: $graph_impl = $graph_collector(some_triples()).unwrap(); let objects: HashSet = g.objects().map(|t| t.unwrap().into_term()).collect(); @@ -549,7 +549,7 @@ macro_rules! test_graph_impl { } #[test] - fn iris() -> Result<(), Box> { + fn iris() -> Result<(), Box> { let g = if $is_gen { $graph_collector(generalized_node_types_triples()).unwrap() } else { @@ -566,7 +566,7 @@ macro_rules! test_graph_impl { } #[test] - fn bnodes() -> Result<(), Box> { + fn bnodes() -> Result<(), Box> { let g = if $is_gen { $graph_collector(generalized_node_types_triples()).unwrap() } else { @@ -581,7 +581,7 @@ macro_rules! test_graph_impl { } #[test] - fn literals() -> Result<(), Box> { + fn literals() -> Result<(), Box> { let g = if $is_gen { $graph_collector(generalized_node_types_triples()).unwrap() } else { @@ -598,7 +598,7 @@ macro_rules! test_graph_impl { } #[test] - fn quoted_triples() -> Result<(), Box> { + fn quoted_triples() -> Result<(), Box> { if $is_gen { let g: $graph_impl = $graph_collector(generalized_node_types_triples()).unwrap(); @@ -638,7 +638,7 @@ macro_rules! test_graph_impl { } #[test] - fn variables() -> Result<(), Box> { + fn variables() -> Result<(), Box> { if $is_gen { let g: $graph_impl = $graph_collector(generalized_node_types_triples()).unwrap(); diff --git a/api/src/term/_native_literal.rs b/api/src/term/_native_literal.rs index b33c3b0e..1b301cee 100644 --- a/api/src/term/_native_literal.rs +++ b/api/src/term/_native_literal.rs @@ -17,7 +17,7 @@ lazy_static::lazy_static! { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// graph.insert(&subject, &rdf::value, 3.14)?; @@ -53,7 +53,7 @@ impl Term for f64 { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// graph.insert(&subject, &rdf::value, 42)?; @@ -89,7 +89,7 @@ impl Term for i32 { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// let answer: isize = 42; @@ -126,7 +126,7 @@ impl Term for isize { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// let answer: usize = 42; @@ -163,7 +163,7 @@ impl Term for usize { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// graph.insert(&subject, &rdfs::label, "hello world")?; @@ -199,7 +199,7 @@ impl Term for str { /// # use sophia_api::term::SimpleTerm; /// # use sophia_api::ns::{rdf, rdfs}; /// # use sophia_iri::IriRef; -/// # fn test(graph: &mut T) -> Result<(), Box> { +/// # fn test(graph: &mut T) -> Result<(), Box> { /// # let subject: IriRef<&'static str> = IriRef::new("")?; /// # /// graph.insert(&subject, &rdf::value, true)?; diff --git a/book/src/ch01_getting_started.md b/book/src/ch01_getting_started.md index 9a2524a4..67669eee 100644 --- a/book/src/ch01_getting_started.md +++ b/book/src/ch01_getting_started.md @@ -41,7 +41,7 @@ graph.insert( let mut nt_stringifier = NtSerializer::new_stringifier(); let example2 = nt_stringifier.serialize_graph(&graph)?.as_str(); println!("The resulting graph:\n{}", example2); -# Ok::<(), Box>(()) +# Ok::<(), Box>(()) ``` You should get the following output: diff --git a/book/src/ch02_rdf_terms.md b/book/src/ch02_rdf_terms.md index 37c5ba00..138e8fab 100644 --- a/book/src/ch02_rdf_terms.md +++ b/book/src/ch02_rdf_terms.md @@ -78,7 +78,7 @@ More precisely, the type returned by [`t.borrow_term()`] is the associated type ### Constructing IRIs ```rust,noplayground -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # # use sophia::{iri::IriRef, api::ns::Namespace}; # let some_text = "http://example.org"; @@ -103,7 +103,7 @@ let iri6 = xsd::string ; ### Constructing literals ```rust,noplayground -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # # use sophia::api::{ns::xsd, term::{LanguageTag, SimpleTerm, Term}}; // use native types for xsd::string, xsd::integer, xsd::double @@ -123,7 +123,7 @@ let lit_date = "2023-11-15" * xsd::date; ### Constructing blank nodes ```rust,noplayground -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # # use sophia::api::term::BnodeId; let b = BnodeId::new_unchecked("x"); @@ -134,7 +134,7 @@ let b = BnodeId::new_unchecked("x"); ### Converting terms into a different type ```rust,noplayground # use sophia::api::{ns::xsd, term::{SimpleTerm, Term}}; -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # let some_term = "42" * xsd::integer; let t1: SimpleTerm = "hello".into_term(); let t2: i32 = some_term.try_into_term()?; diff --git a/book/src/ch04_rdf_graphs.md b/book/src/ch04_rdf_graphs.md index bc76524e..6d399958 100644 --- a/book/src/ch04_rdf_graphs.md +++ b/book/src/ch04_rdf_graphs.md @@ -11,7 +11,7 @@ This is achieved with the [`Graph::triples`] method: ```rust,noplayground # use sophia::api::prelude::*; # use sophia::inmem::graph::LightGraph; -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # let g = LightGraph::new(); for result in g.triples() { let triple = result?; @@ -69,7 +69,7 @@ Inserting (resp. removing) a triple that is already (resp. not) present in the g ```rust,noplayground # use sophia::{api::{ns::rdf, prelude::*}, iri::*}; /// Example: increment the rdf:value of a given subject -# fn f(mut g: G) -> Result<(), Box> { +# fn f(mut g: G) -> Result<(), Box> { # let s = Iri::new_unchecked("https://example.org/foo"); let old_value: i32 = g.triples_matching([s], [rdf::value], Any) .next() @@ -109,7 +109,7 @@ and are described in more detail in the [next chapter](./ch05_term_matchers.md). ```rust,noplayground # use sophia::{api::{ns::{Namespace, rdf}, prelude::*}, inmem::graph::FastGraph}; -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { let mut g = FastGraph::new(); let ex = Namespace::new_unchecked("https://example.org/ns#"); let alice = ex.get_unchecked("alice"); @@ -131,7 +131,7 @@ g.insert( ```rust,noplayground # use sophia::{api::prelude::*, inmem::graph::FastGraph, iri::Iri}; -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { # let big_graph = FastGraph::new(); // Extract all triples about 'alice' from big_graph in a new graph let alice = Iri::new_unchecked("https://example.org/ns#alice"); @@ -152,7 +152,7 @@ However, most types implementing [`Graph`] should implement [`CollectibleGraph`] # use std::{io::BufReader, fs::File}; use sophia::turtle::parser::turtle; -# fn main() -> Result<(), Box> { +# fn main() -> Result<(), Box> { dbg!(std::env::current_dir()); let f = BufReader::new(File::open("../sophia_doap.ttl")?); let graph: FastGraph = turtle::parse_bufread(f) diff --git a/inmem/src/index.rs b/inmem/src/index.rs index 75342db4..273cbb68 100644 --- a/inmem/src/index.rs +++ b/inmem/src/index.rs @@ -195,7 +195,7 @@ mod test { use sophia_api::term::BnodeId; #[test] - fn simple_term_index() -> Result<(), Box> { + fn simple_term_index() -> Result<(), Box> { let ex = Namespace::new_unchecked("https://example.com/ns/"); let exa = ex.get("a")?; let exb = ex.get("b")?; diff --git a/iri/src/lib.rs b/iri/src/lib.rs index 1c81ed89..67e9f4e1 100644 --- a/iri/src/lib.rs +++ b/iri/src/lib.rs @@ -41,6 +41,7 @@ pub mod wrap_macro_examples; #[cfg(any(test, feature = "test_data"))] pub mod test; +use std::convert::Infallible; #[cfg(not(feature = "threadsafe_err"))] pub use std::error::Error; #[cfg(feature = "threadsafe_err")] @@ -48,4 +49,4 @@ pub use ThreadSafeError as Error; /// An error trait meant to enable sending errors safely across threads. pub trait ThreadSafeError: std::error::Error + Send + Sync + 'static {} -impl ThreadSafeError for E where E: std::error::Error + Send + Sync + 'static {} +impl ThreadSafeError for E where E: std::error::Error + Send + Sync + 'static + ?Sized {} diff --git a/isomorphism/src/test.rs b/isomorphism/src/test.rs index a0c56b4b..b1130178 100644 --- a/isomorphism/src/test.rs +++ b/isomorphism/src/test.rs @@ -1,7 +1,6 @@ use super::*; use sophia_api::ns::xsd; use sophia_api::term::{assert_consistent_term_impl, BnodeId, IriRef, Term, TermKind}; -use sophia_api::Error; use sophia_api::MownStr; const FOAF_KNOWS: MyTerm = MyTerm::Iri("http://xmlns.com/foaf/0.1/knows"); @@ -12,7 +11,7 @@ const LIT_ALICE: MyTerm = MyTerm::String("alice"); const LIT_BOB: MyTerm = MyTerm::String("bob"); #[test] -fn no_bnode() -> Result<(), Box> { +fn no_bnode() -> Result<(), Box> { let make_dataset = |i1: &'static str, i2: &'static str| -> Vec<([MyTerm; 3], Option)> { let i1 = MyTerm::Iri(i1); let i2 = MyTerm::Iri(i2); @@ -47,7 +46,7 @@ fn no_bnode() -> Result<(), Box> { } #[test] -fn simple() -> Result<(), Box> { +fn simple() -> Result<(), Box> { let make_dataset = |b1: &'static str, b2: &'static str| -> Vec<([MyTerm; 3], Option)> { let b1 = MyTerm::Bnode(b1); let b2 = MyTerm::Bnode(b2); @@ -83,7 +82,7 @@ fn simple() -> Result<(), Box> { } #[test] -fn no_bnode_quoted_triple() -> Result<(), Box> { +fn no_bnode_quoted_triple() -> Result<(), Box> { const A: MyTerm = MyTerm::Iri("#a"); const B: MyTerm = MyTerm::Iri("#b"); const C: MyTerm = MyTerm::Iri("#c"); @@ -115,7 +114,7 @@ fn no_bnode_quoted_triple() -> Result<(), Box> { } #[test] -fn quoted_triple() -> Result<(), Box> { +fn quoted_triple() -> Result<(), Box> { const A: MyTerm = MyTerm::Bnode("a"); const B: MyTerm = MyTerm::Bnode("b"); const C: MyTerm = MyTerm::Bnode("c"); @@ -159,7 +158,7 @@ fn make_chain(ids: &'static str) -> Vec<[MyTerm; 4]> { } #[test] -fn chain() -> Result<(), Box> { +fn chain() -> Result<(), Box> { let d1 = make_chain("abcdefghij"); assert!(isomorphic_datasets(&d1, &d1)?); let d2 = make_chain("EDCBAJIHGF"); @@ -172,7 +171,7 @@ fn chain() -> Result<(), Box> { } #[test] -fn cycle2() -> Result<(), Box> { +fn cycle2() -> Result<(), Box> { let d1 = make_chain("aba"); assert!(isomorphic_datasets(&d1, &d1)?); let d2 = make_chain("BAB"); @@ -182,7 +181,7 @@ fn cycle2() -> Result<(), Box> { } #[test] -fn cycle_long() -> Result<(), Box> { +fn cycle_long() -> Result<(), Box> { let d1 = make_chain("abcdefghia"); assert!(isomorphic_datasets(&d1, &d1)?); let d2 = make_chain("EBCDAIGHFE"); @@ -196,7 +195,7 @@ fn cycle_long() -> Result<(), Box> { #[test] #[ignore] -fn cycle_pathological() -> Result<(), Box> { +fn cycle_pathological() -> Result<(), Box> { // This case is tricky (and does not work with the current implementation). // Both graphs contain the same number of (blank nodes) and the same number of arcs. // All blank nodes are locally undistinguishable from each other: @@ -212,7 +211,7 @@ fn cycle_pathological() -> Result<(), Box> { } #[test] -fn cycle_almost_pathological() -> Result<(), Box> { +fn cycle_almost_pathological() -> Result<(), Box> { // This is uses the same graphs as above (cycle_pathological), // but *one* of the blank nodes is distinguished by an additional property, // which breaks symmetry and allow the algorithm to give the correct answer. @@ -248,7 +247,7 @@ fn make_clique(ids: &'static str) -> Vec<[MyTerm; 4]> { } #[test] -fn clique() -> Result<(), Box> { +fn clique() -> Result<(), Box> { let d1 = make_clique("abcde"); assert!(isomorphic_datasets(&d1, &d1)?); @@ -279,7 +278,7 @@ fn make_tree(ids: &'static str) -> Vec<[MyTerm; 4]> { } #[test] -fn tree() -> Result<(), Box> { +fn tree() -> Result<(), Box> { let d1 = make_tree("abcdefghij"); assert!(isomorphic_datasets(&d1, &d1)?); @@ -293,7 +292,7 @@ fn tree() -> Result<(), Box> { } #[test] -fn predicate_and_gname() -> Result<(), Box> { +fn predicate_and_gname() -> Result<(), Box> { let rel = MyTerm::Iri("tag:rel"); let b1 = MyTerm::Bnode("b1"); let b2 = MyTerm::Bnode("b2"); diff --git a/jsonld/src/serializer/test.rs b/jsonld/src/serializer/test.rs index edfe09ea..96bc2dc2 100644 --- a/jsonld/src/serializer/test.rs +++ b/jsonld/src/serializer/test.rs @@ -113,4 +113,4 @@ fn native_value() -> TestResult { Ok(()) } -pub type TestResult = Result<(), Box>; +pub type TestResult = Result<(), Box>; diff --git a/resource/src/lib.rs b/resource/src/lib.rs index b71ebb69..508961d5 100644 --- a/resource/src/lib.rs +++ b/resource/src/lib.rs @@ -72,7 +72,7 @@ mod test { pub const F5_LEN: usize = 20; pub type MyGraph = Vec<[SimpleTerm<'static>; 3]>; - pub type TestResult = Result<(), Box>; + pub type TestResult = Result<(), Box>; pub fn make_loader() -> LocalLoader { let ns = NS.map_unchecked(MownStr::from); diff --git a/resource/src/loader/_error.rs b/resource/src/loader/_error.rs index b877a05e..7368f477 100644 --- a/resource/src/loader/_error.rs +++ b/resource/src/loader/_error.rs @@ -20,7 +20,7 @@ pub enum LoaderError { CantGuessSyntax(IriBuf), /// An error was encountered while parsing the data into an RDF graph #[error("Can not parse {0:?}: {1}")] - ParseError(IriBuf, Box), + ParseError(IriBuf, Box), } impl LoaderError { diff --git a/resource/src/resource/test.rs b/resource/src/resource/test.rs index a573374d..56948db5 100644 --- a/resource/src/resource/test.rs +++ b/resource/src/resource/test.rs @@ -597,6 +597,6 @@ fn no_reload() -> TestResult { Ok(()) } -fn make_rsc(iri: Iri<&str>) -> Result, Box> { +fn make_rsc(iri: Iri<&str>) -> Result, Box> { Ok(make_loader().arced().get_resource(iri)?) } diff --git a/sophia/examples/canonicalize.rs b/sophia/examples/canonicalize.rs index 13454710..5885d1dc 100644 --- a/sophia/examples/canonicalize.rs +++ b/sophia/examples/canonicalize.rs @@ -20,7 +20,7 @@ use sophia::turtle::parser::nq; use sophia_c14n::hash::Sha256; use sophia_c14n::rdfc10::{DEFAULT_DEPTH_FACTOR, DEFAULT_PERMUTATION_LIMIT}; -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { let input = BufReader::new(stdin()); let dataset: MyDataset = nq::parse_bufread(input).collect_quads()?; let output = BufWriter::new(stdout()); diff --git a/sophia/examples/jsonld-context.rs b/sophia/examples/jsonld-context.rs index efd8dcf5..a01f5aa8 100644 --- a/sophia/examples/jsonld-context.rs +++ b/sophia/examples/jsonld-context.rs @@ -14,7 +14,7 @@ use sophia::{ turtle::serializer::trig::{TrigConfig, TrigSerializer}, }; -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { let mut args = std::env::args(); let json_ld_path = args.nth(1).expect("Missing jsonld file."); let context_path = args.next(); @@ -42,7 +42,7 @@ fn main() -> Result<(), Box> { Ok(()) } -fn to_trig(quads: impl QuadSource) -> Result> { +fn to_trig(quads: impl QuadSource) -> Result> { let mut stringifier = TrigSerializer::new_stringifier_with_config(TrigConfig::new().with_pretty(true)); stringifier.serialize_quads(quads)?; diff --git a/turtle/src/parser/gnq.rs b/turtle/src/parser/gnq.rs index 56b14f9d..442d2f77 100644 --- a/turtle/src/parser/gnq.rs +++ b/turtle/src/parser/gnq.rs @@ -37,7 +37,7 @@ mod test { type MyDataset = Vec>>; #[test] - fn test_simple_gnq_string() -> std::result::Result<(), Box> { + fn test_simple_gnq_string() -> std::result::Result<(), Box> { let nq = r#" _:b1. _:b1 . diff --git a/turtle/src/parser/gtrig.rs b/turtle/src/parser/gtrig.rs index dcb56036..5fce276c 100644 --- a/turtle/src/parser/gtrig.rs +++ b/turtle/src/parser/gtrig.rs @@ -46,7 +46,7 @@ mod test { type MyDataset = Vec>>; #[test] - fn test_simple_gtrig_string() -> std::result::Result<(), Box> { + fn test_simple_gtrig_string() -> std::result::Result<(), Box> { let gtrig = r#" @prefix : . diff --git a/turtle/src/parser/nq.rs b/turtle/src/parser/nq.rs index 32517a69..adac0bf3 100644 --- a/turtle/src/parser/nq.rs +++ b/turtle/src/parser/nq.rs @@ -37,7 +37,7 @@ mod test { type MyDataset = Vec>>; #[test] - fn test_simple_nq_string() -> std::result::Result<(), Box> { + fn test_simple_nq_string() -> std::result::Result<(), Box> { let nq = r#" _:b1. _:b1 . diff --git a/turtle/src/parser/nt.rs b/turtle/src/parser/nt.rs index 423ae63c..825f26af 100644 --- a/turtle/src/parser/nt.rs +++ b/turtle/src/parser/nt.rs @@ -36,7 +36,7 @@ mod test { type MyGraph = Vec<[SimpleTerm<'static>; 3]>; #[test] - fn test_simple_nt_string() -> std::result::Result<(), Box> { + fn test_simple_nt_string() -> std::result::Result<(), Box> { let nt = r#" _:b1. _:b1 . diff --git a/turtle/src/parser/trig.rs b/turtle/src/parser/trig.rs index 66cca560..6ef9ace5 100644 --- a/turtle/src/parser/trig.rs +++ b/turtle/src/parser/trig.rs @@ -46,7 +46,7 @@ mod test { type MyDataset = Vec>>; #[test] - fn test_simple_trig_string() -> std::result::Result<(), Box> { + fn test_simple_trig_string() -> std::result::Result<(), Box> { let trig = r#" @prefix : . diff --git a/turtle/src/parser/turtle.rs b/turtle/src/parser/turtle.rs index 43ee961a..a5531be2 100644 --- a/turtle/src/parser/turtle.rs +++ b/turtle/src/parser/turtle.rs @@ -43,7 +43,7 @@ mod test { type MyGraph = Vec<[SimpleTerm<'static>; 3]>; #[test] - fn test_simple_turtle_string() -> std::result::Result<(), Box> { + fn test_simple_turtle_string() -> std::result::Result<(), Box> { let turtle = r#" @prefix : . diff --git a/turtle/src/serializer/_pretty.rs b/turtle/src/serializer/_pretty.rs index 8a38f318..b6ffe41a 100644 --- a/turtle/src/serializer/_pretty.rs +++ b/turtle/src/serializer/_pretty.rs @@ -792,7 +792,7 @@ pub(crate) mod test { } #[test] - fn relative_iri() -> Result<(), Box> { + fn relative_iri() -> Result<(), Box> { let iri = IriRef::new_unchecked(""); let graph = vec![[iri, iri, iri]]; let config = TurtleConfig::new().with_pretty(true); diff --git a/turtle/src/serializer/nq.rs b/turtle/src/serializer/nq.rs index a430f28a..63c3eccb 100644 --- a/turtle/src/serializer/nq.rs +++ b/turtle/src/serializer/nq.rs @@ -115,7 +115,7 @@ pub(crate) mod test { use sophia_iri::Iri; #[test] - fn graph() -> Result<(), Box> { + fn graph() -> Result<(), Box> { let me = BnodeId::new_unchecked("me"); let mut d: Vec>> = vec![]; MutableDataset::insert( diff --git a/turtle/src/serializer/nt.rs b/turtle/src/serializer/nt.rs index 33a062a6..763b6b14 100644 --- a/turtle/src/serializer/nt.rs +++ b/turtle/src/serializer/nt.rs @@ -218,7 +218,7 @@ pub(crate) mod test { use sophia_iri::Iri; #[test] - fn graph() -> Result<(), Box> { + fn graph() -> Result<(), Box> { let me = BnodeId::new_unchecked("me"); let mut g: Vec<[SimpleTerm<'static>; 3]> = vec![]; MutableGraph::insert( diff --git a/turtle/src/serializer/trig.rs b/turtle/src/serializer/trig.rs index 63a1c7d2..33887a89 100644 --- a/turtle/src/serializer/trig.rs +++ b/turtle/src/serializer/trig.rs @@ -177,7 +177,7 @@ pub(crate) mod test { ]; #[test] - fn roundtrip_not_pretty() -> Result<(), Box> { + fn roundtrip_not_pretty() -> Result<(), Box> { for ttl in TESTS { println!("==========\n{}\n----------", ttl); let g1: Vec> = crate::parser::trig::parse_str(ttl).collect_quads()?; @@ -195,7 +195,7 @@ pub(crate) mod test { } #[test] - fn roundtrip_pretty() -> Result<(), Box> { + fn roundtrip_pretty() -> Result<(), Box> { for ttl in TESTS { println!("==========\n{}\n----------", ttl); let g1: Vec> = crate::parser::trig::parse_str(ttl).collect_quads()?; diff --git a/turtle/src/serializer/turtle.rs b/turtle/src/serializer/turtle.rs index 92acc0f6..37d70d3e 100644 --- a/turtle/src/serializer/turtle.rs +++ b/turtle/src/serializer/turtle.rs @@ -211,7 +211,6 @@ impl Stringifier for TurtleSerializer> { pub(crate) mod test { use super::*; use sophia_api::graph::Graph; - use sophia_api::Error; use sophia_isomorphism::isomorphic_graphs; const TESTS: &[&str] = &[ @@ -246,7 +245,7 @@ pub(crate) mod test { ]; #[test] - fn roundtrip_not_pretty() -> Result<(), Box> { + fn roundtrip_not_pretty() -> Result<(), Box> { for ttl in TESTS { println!("==========\n{}\n----------", ttl); let g1: Vec<[SimpleTerm; 3]> = @@ -266,7 +265,7 @@ pub(crate) mod test { } #[test] - fn roundtrip_pretty() -> Result<(), Box> { + fn roundtrip_pretty() -> Result<(), Box> { for ttl in TESTS { println!("==========\n{}\n----------", ttl); let g1: Vec<[SimpleTerm; 3]> = diff --git a/xml/src/parser.rs b/xml/src/parser.rs index 6816ae63..e550bd1e 100644 --- a/xml/src/parser.rs +++ b/xml/src/parser.rs @@ -46,7 +46,7 @@ mod test { type MyGraph = Vec<[SimpleTerm<'static>; 3]>; #[test] - fn test_simple_xml_string() -> std::result::Result<(), Box> { + fn test_simple_xml_string() -> std::result::Result<(), Box> { let xml = r#" diff --git a/xml/src/serializer.rs b/xml/src/serializer.rs index ddde6d2f..ec4f42f1 100644 --- a/xml/src/serializer.rs +++ b/xml/src/serializer.rs @@ -138,7 +138,7 @@ pub(crate) mod test { "#]; #[test] - fn roundtrip() -> Result<(), Box> { + fn roundtrip() -> Result<(), Box> { for rdfxml in TESTS { println!("==========\n{}\n----------", rdfxml); let g1: Vec<[SimpleTerm; 3]> = crate::parser::parse_str(rdfxml).collect_triples()?; @@ -156,7 +156,7 @@ pub(crate) mod test { } #[test] - fn roundtrip_with_ident() -> Result<(), Box> { + fn roundtrip_with_ident() -> Result<(), Box> { let config = RdfXmlConfig::new().with_indentation(4); for rdfxml in TESTS { println!("==========\n{}\n----------", rdfxml); From 773a5eefa79a9c0b83615e70d00c556ceeac7b48 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 13:57:52 -0500 Subject: [PATCH 14/20] cargo fix --- iri/src/lib.rs | 1 - turtle/src/serializer/trig.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/iri/src/lib.rs b/iri/src/lib.rs index 67e9f4e1..4cd77ee7 100644 --- a/iri/src/lib.rs +++ b/iri/src/lib.rs @@ -41,7 +41,6 @@ pub mod wrap_macro_examples; #[cfg(any(test, feature = "test_data"))] pub mod test; -use std::convert::Infallible; #[cfg(not(feature = "threadsafe_err"))] pub use std::error::Error; #[cfg(feature = "threadsafe_err")] diff --git a/turtle/src/serializer/trig.rs b/turtle/src/serializer/trig.rs index 33887a89..35f02f9b 100644 --- a/turtle/src/serializer/trig.rs +++ b/turtle/src/serializer/trig.rs @@ -109,7 +109,7 @@ impl Stringifier for TrigSerializer> { pub(crate) mod test { use super::*; use sophia_api::term::SimpleTerm; - use sophia_api::Error; + use sophia_api::{dataset::Dataset, quad::Spog}; use sophia_isomorphism::isomorphic_datasets; From 60815846478bd82e4b365278665b18129f3c273b Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 14:29:16 -0500 Subject: [PATCH 15/20] handle LoaderError dyn --- api/src/dataset.rs | 1 + api/src/graph.rs | 1 + api/src/source/filter.rs | 4 ++-- c14n/src/rdfc10.rs | 2 +- resource/src/loader/_error.rs | 2 +- resource/src/resource/_error.rs | 2 +- turtle/src/serializer/_pretty.rs | 10 +++++----- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/api/src/dataset.rs b/api/src/dataset.rs index 8405c5c5..cf38d755 100644 --- a/api/src/dataset.rs +++ b/api/src/dataset.rs @@ -609,6 +609,7 @@ mod check_implementability { /// - a list of terms (either atoms or index of quad) /// - a list of triples (SPO indexes) /// - a list of named graphs associated the triple indexes contained in the graph + /// /// This avoids the need to store arbitrarily nested triples. /// NB: unasserted triples are not used in any quoted graph. use super::*; diff --git a/api/src/graph.rs b/api/src/graph.rs index 83df2324..5e070d34 100644 --- a/api/src/graph.rs +++ b/api/src/graph.rs @@ -530,6 +530,7 @@ mod check_implementability { /// where the graph maintains /// - a list of terms (either atoms or index of triple) /// - a list of triples (SPO indexes, plus an 'asserted' flag) + /// /// This avoids the need to store arbitrarily nested triples. use super::*; use crate::term::SimpleTerm; diff --git a/api/src/source/filter.rs b/api/src/source/filter.rs index de68e4b8..6297b7fc 100644 --- a/api/src/source/filter.rs +++ b/api/src/source/filter.rs @@ -130,7 +130,7 @@ mod test { ]; let mut h: Vec<[SimpleTerm; 3]> = vec![]; g.triples() - .filter_triples(|t| !Term::eq(t.p(), &ez_term(":e"))) + .filter_triples(|t| !Term::eq(t.p(), ez_term(":e"))) .for_each_triple(|t| { h.insert_triple(t).unwrap(); }) @@ -153,7 +153,7 @@ mod test { ]; let mut h: Vec> = vec![]; d.quads() - .filter_quads(|q| !Term::eq(q.p(), &ez_term(":e"))) + .filter_quads(|q| !Term::eq(q.p(), ez_term(":e"))) .for_each_quad(|q| { h.insert_quad(q).unwrap(); }) diff --git a/c14n/src/rdfc10.rs b/c14n/src/rdfc10.rs index e48453cb..340ac350 100644 --- a/c14n/src/rdfc10.rs +++ b/c14n/src/rdfc10.rs @@ -337,7 +337,7 @@ impl<'a, H: HashFunction, T: Term> C14nState<'a, H, T> { // Step 5 let mut ret_issuer: Option = None; for (related_hash, mut blank_node) in hn.into_iter() { - data_to_hash.update(&hex(&related_hash)); + data_to_hash.update(hex(&related_hash)); let mut chosen_path = String::new(); let mut chosen_issuer: Option = None; // Step 5.4 diff --git a/resource/src/loader/_error.rs b/resource/src/loader/_error.rs index 7368f477..b877a05e 100644 --- a/resource/src/loader/_error.rs +++ b/resource/src/loader/_error.rs @@ -20,7 +20,7 @@ pub enum LoaderError { CantGuessSyntax(IriBuf), /// An error was encountered while parsing the data into an RDF graph #[error("Can not parse {0:?}: {1}")] - ParseError(IriBuf, Box), + ParseError(IriBuf, Box), } impl LoaderError { diff --git a/resource/src/resource/_error.rs b/resource/src/resource/_error.rs index 94cc63b8..a61fb7cb 100644 --- a/resource/src/resource/_error.rs +++ b/resource/src/resource/_error.rs @@ -102,7 +102,7 @@ impl From for ResourceError { } } -impl std::error::Error for ResourceError {} +impl std::error::Error for ResourceError where E: sophia_api::Error {} /// A result whose error is a [`ResourceError`] pub type ResourceResult = Result::Error>>; diff --git a/turtle/src/serializer/_pretty.rs b/turtle/src/serializer/_pretty.rs index b6ffe41a..62c34570 100644 --- a/turtle/src/serializer/_pretty.rs +++ b/turtle/src/serializer/_pretty.rs @@ -2,13 +2,13 @@ //! //! Possible improvements: //! 1. PrettifiableDataset should encapsulate some of the "indexes" built by Prettifier -//! (labelled, subject_types, named_graphs) -//! and build directly in CollectibleDataset::from_quad_source(). +//! (labelled, subject_types, named_graphs) +//! and build directly in CollectibleDataset::from_quad_source(). //! //! 2. Instead of writing directly to the output, -//! generate a hierarchical structure, -//! and decide on line breaks and indentation based on the overall structure, -//! rather than a priori. +//! generate a hierarchical structure, +//! and decide on line breaks and indentation based on the overall structure, +//! rather than a priori. use super::turtle::TurtleConfig; use regex::Regex; From 33673d7aa1b17529c885b9347f5fa7111e9a7b30 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Thu, 25 Jul 2024 14:43:25 -0500 Subject: [PATCH 16/20] get rid of ?Sized --- iri/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iri/src/lib.rs b/iri/src/lib.rs index 4cd77ee7..1c81ed89 100644 --- a/iri/src/lib.rs +++ b/iri/src/lib.rs @@ -48,4 +48,4 @@ pub use ThreadSafeError as Error; /// An error trait meant to enable sending errors safely across threads. pub trait ThreadSafeError: std::error::Error + Send + Sync + 'static {} -impl ThreadSafeError for E where E: std::error::Error + Send + Sync + 'static + ?Sized {} +impl ThreadSafeError for E where E: std::error::Error + Send + Sync + 'static {} From 265837fcc16e40339414514ab5f46ccc10acd783 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Fri, 26 Jul 2024 15:29:31 -0500 Subject: [PATCH 17/20] partial revert --- api/src/dataset.rs | 2 +- api/src/graph.rs | 2 +- api/src/serializer.rs | 4 ++-- api/src/source.rs | 2 +- api/src/source/_stream_error.rs | 2 +- api/src/source/convert.rs | 4 ++-- api/src/source/filter.rs | 6 +++--- api/src/sparql.rs | 2 +- api/src/term.rs | 2 +- c14n/src/lib.rs | 2 +- c14n/src/rdfc10.rs | 2 +- inmem/src/index.rs | 2 +- jsonld/src/parser/source.rs | 2 +- resource/src/loader/_error.rs | 2 +- resource/src/resource/_error.rs | 2 +- rio/src/parser.rs | 2 +- rio/src/serializer.rs | 4 ++-- 17 files changed, 22 insertions(+), 22 deletions(-) diff --git a/api/src/dataset.rs b/api/src/dataset.rs index cf38d755..da57b605 100644 --- a/api/src/dataset.rs +++ b/api/src/dataset.rs @@ -12,7 +12,7 @@ use crate::quad::{iter_spog, Quad}; use crate::source::{IntoSource, QuadSource, StreamResult}; use crate::term::matcher::{GraphNameMatcher, TermMatcher}; use crate::term::{GraphName, SimpleTerm, Term}; -use crate::Error; + use resiter::{filter::*, filter_map::*, flat_map::*, map::*}; mod _foreign_impl; diff --git a/api/src/graph.rs b/api/src/graph.rs index 5e070d34..fb16dc91 100644 --- a/api/src/graph.rs +++ b/api/src/graph.rs @@ -9,7 +9,7 @@ use crate::dataset::adapter::GraphAsDataset; use crate::source::{IntoSource, StreamResult, TripleSource}; use crate::term::{matcher::TermMatcher, SimpleTerm, Term}; use crate::triple::Triple; -use crate::Error; + use resiter::{filter::*, flat_map::*, map::*}; mod _foreign_impl; diff --git a/api/src/serializer.rs b/api/src/serializer.rs index b79a909f..c87f0daa 100644 --- a/api/src/serializer.rs +++ b/api/src/serializer.rs @@ -18,7 +18,7 @@ use crate::source::*; /// A triple serializer writes triples according to a given format. pub trait TripleSerializer { /// The error type that may be raised during serialization. - type Error: 'static + crate::Error; + type Error: std::error::Error + Send + Sync + 'static; /// Serialize all triples from the given [`TripleSource`]. fn serialize_triples( @@ -47,7 +47,7 @@ pub trait TripleSerializer { /// A quad serializer writes quads according to a given format. pub trait QuadSerializer { /// The error type that may be raised during serialization. - type Error: 'static + crate::Error; + type Error: std::error::Error + Send + Sync + 'static; /// Serialize all quads from the given [`QuadSource`]. fn serialize_quads( diff --git a/api/src/source.rs b/api/src/source.rs index 28c010a5..97b25c2e 100644 --- a/api/src/source.rs +++ b/api/src/source.rs @@ -56,7 +56,7 @@ //! [`for_each_quad`]: QuadSource::for_each_quad //! [higher-rank trait bounds]: https://doc.rust-lang.org/nomicon/hrtb.html -use crate::Error; + pub mod convert; pub mod filter; diff --git a/api/src/source/_stream_error.rs b/api/src/source/_stream_error.rs index 9990a353..189f4b06 100644 --- a/api/src/source/_stream_error.rs +++ b/api/src/source/_stream_error.rs @@ -1,4 +1,4 @@ -use crate::Error; + /// A error that is raised by functions that move fallible `Source`s into /// fallible `Sinks`. diff --git a/api/src/source/convert.rs b/api/src/source/convert.rs index 85ddb29c..a2b574f1 100644 --- a/api/src/source/convert.rs +++ b/api/src/source/convert.rs @@ -16,7 +16,7 @@ impl Source for ToQuads { fn try_for_some_item(&mut self, mut f: F) -> super::StreamResult where - E: crate::Error, + E: std::error::Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), E>, { self.0.try_for_some_triple(|t| { @@ -40,7 +40,7 @@ impl Source for ToTriples { fn try_for_some_item(&mut self, mut f: F) -> super::StreamResult where - E: crate::Error, + E: std::error::Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), E>, { self.0.try_for_some_quad(|q| { diff --git a/api/src/source/filter.rs b/api/src/source/filter.rs index 6297b7fc..61550d14 100644 --- a/api/src/source/filter.rs +++ b/api/src/source/filter.rs @@ -22,7 +22,7 @@ where fn try_for_some_item(&mut self, mut f: F) -> StreamResult where - E: Error, + E: std::error::Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), E>, { let p = &mut self.predicate; @@ -55,7 +55,7 @@ mod _triple { fn try_for_some_item(&mut self, mut f: F) -> StreamResult where - E: Error, + E: std::error::Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), E>, { self.0.try_for_some_item(|i| f(S::i2t(i))) @@ -84,7 +84,7 @@ mod _quad { fn try_for_some_item(&mut self, mut f: F) -> StreamResult where - E: Error, + E: std::error::Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), E>, { self.0.try_for_some_item(|i| f(S::i2q(i))) diff --git a/api/src/sparql.rs b/api/src/sparql.rs index f48b441b..09374f45 100644 --- a/api/src/sparql.rs +++ b/api/src/sparql.rs @@ -29,7 +29,7 @@ use crate::source::TripleSource; use crate::term::Term; -use crate::Error; + use std::borrow::Borrow; /// A dataset that can be queried with SPARQL. diff --git a/api/src/term.rs b/api/src/term.rs index 75834ceb..ba810f3c 100644 --- a/api/src/term.rs +++ b/api/src/term.rs @@ -575,7 +575,7 @@ pub trait FromTerm: Sized { /// See also [`FromTerm`] pub trait TryFromTerm: Sized { /// The error type produced when failing to copy a given term - type Error: 'static + crate::Error; + type Error: std::error::Error + Send + Sync + 'static; /// Try to copy `term` into an instance of this type. fn try_from_term(term: T) -> Result; } diff --git a/c14n/src/lib.rs b/c14n/src/lib.rs index ea553c66..31da7d47 100644 --- a/c14n/src/lib.rs +++ b/c14n/src/lib.rs @@ -26,7 +26,7 @@ use thiserror::Error; /// Canonicalization error. #[derive(Debug, Error)] -pub enum C14nError { +pub enum C14nError { /// The dataset raised an error during canonicalization #[error("Error from dataset: {0}")] Dataset(#[from] E), diff --git a/c14n/src/rdfc10.rs b/c14n/src/rdfc10.rs index 340ac350..b7e42bf7 100644 --- a/c14n/src/rdfc10.rs +++ b/c14n/src/rdfc10.rs @@ -302,7 +302,7 @@ impl<'a, H: HashFunction, T: Term> C14nState<'a, H, T> { } /// Implements https://www.w3.org/TR/rdf-canon/#hash-nd-quads - fn hash_n_degree_quads( + fn hash_n_degree_quads( &self, identifier: &str, issuer: &BnodeIssuer, diff --git a/inmem/src/index.rs b/inmem/src/index.rs index 273cbb68..0975f4a4 100644 --- a/inmem/src/index.rs +++ b/inmem/src/index.rs @@ -1,6 +1,6 @@ //! A [`TermIndex`] is a bidirectional assocuation of [terms](Term) with short numeric [indices](Index). use sophia_api::term::{FromTerm, GraphName, SimpleTerm, Term}; -use sophia_api::Error; + use std::collections::hash_map::Entry; use std::collections::HashMap; diff --git a/jsonld/src/parser/source.rs b/jsonld/src/parser/source.rs index 6dff84c6..1445a965 100644 --- a/jsonld/src/parser/source.rs +++ b/jsonld/src/parser/source.rs @@ -33,7 +33,7 @@ impl Source for JsonLdQuadSource { fn try_for_some_item(&mut self, mut f: F) -> StreamResult where - E: sophia_api::Error, + E: std::error::Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), E>, { match self { diff --git a/resource/src/loader/_error.rs b/resource/src/loader/_error.rs index b877a05e..f33febd0 100644 --- a/resource/src/loader/_error.rs +++ b/resource/src/loader/_error.rs @@ -20,7 +20,7 @@ pub enum LoaderError { CantGuessSyntax(IriBuf), /// An error was encountered while parsing the data into an RDF graph #[error("Can not parse {0:?}: {1}")] - ParseError(IriBuf, Box), + ParseError(IriBuf, Box), } impl LoaderError { diff --git a/resource/src/resource/_error.rs b/resource/src/resource/_error.rs index a61fb7cb..c1ba1d65 100644 --- a/resource/src/resource/_error.rs +++ b/resource/src/resource/_error.rs @@ -102,7 +102,7 @@ impl From for ResourceError { } } -impl std::error::Error for ResourceError where E: sophia_api::Error {} +impl std::error::Error for ResourceError where E: std::error::Error + Send + Sync + 'static {} /// A result whose error is a [`ResourceError`] pub type ResourceResult = Result::Error>>; diff --git a/rio/src/parser.rs b/rio/src/parser.rs index e92d791d..64465938 100644 --- a/rio/src/parser.rs +++ b/rio/src/parser.rs @@ -8,7 +8,7 @@ use crate::model::Trusted; use sophia_api::source::{StreamError, StreamError::*, StreamResult}; -use sophia_api::Error; + /// Wrap a Rio [`TriplesParser`](rio_api::parser::TriplesParser) /// into a Sophia [`TripleSource`](sophia_api::source::TripleSource). diff --git a/rio/src/serializer.rs b/rio/src/serializer.rs index c8cb1d95..e4b41f1b 100644 --- a/rio/src/serializer.rs +++ b/rio/src/serializer.rs @@ -21,7 +21,7 @@ pub fn rio_format_triples( ) -> StreamResult<(), TS::Error, TF::Error> where TF: TriplesFormatter, - TF::Error: sophia_api::Error, + TF::Error: std::error::Error + Send + Sync + 'static, TS: TripleSource, { triples.try_for_each_triple(|t| { @@ -42,7 +42,7 @@ pub fn rio_format_quads( ) -> StreamResult<(), QS::Error, QF::Error> where QF: QuadsFormatter, - QF::Error: sophia_api::Error, + QF::Error: std::error::Error + Send + Sync + 'static, QS: QuadSource, { quads.try_for_each_quad(|q| { From 5463e5231bdc56aad85a3d66b1252ce3a2347120 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Fri, 26 Jul 2024 15:37:31 -0500 Subject: [PATCH 18/20] compiling revert --- api/Cargo.toml | 1 - api/src/dataset.rs | 4 ++-- api/src/dataset/adapter.rs | 2 ++ api/src/graph.rs | 4 ++-- api/src/lib.rs | 2 -- api/src/source.rs | 12 +++++------- api/src/source/_quad.rs | 6 ++++-- api/src/source/_stream_error.rs | 4 ++-- api/src/source/_triple.rs | 6 ++++-- api/src/source/filter_map.rs | 4 ++-- api/src/source/map.rs | 4 ++-- api/src/sparql.rs | 4 ++-- inmem/src/index.rs | 2 +- iri/Cargo.toml | 1 - iri/src/lib.rs | 9 --------- resource/src/resource/_error.rs | 22 ++++++++++++++++------ rio/src/parser.rs | 23 ++++++++++++----------- sophia/Cargo.toml | 1 - 18 files changed, 56 insertions(+), 55 deletions(-) diff --git a/api/Cargo.toml b/api/Cargo.toml index 477ff2c3..a9cb4b91 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -23,7 +23,6 @@ all_tests = [] test_macro = [] # This feature (enabled by default) makes prefixes seralizable/deserializable serde = ["dep:serde"] -threadsafe_err = ["sophia_iri/threadsafe_err"] [dependencies] diff --git a/api/src/dataset.rs b/api/src/dataset.rs index da57b605..b1821c7b 100644 --- a/api/src/dataset.rs +++ b/api/src/dataset.rs @@ -56,7 +56,7 @@ pub trait Dataset { where Self: 'x; /// The error type that this dataset may raise. - type Error: Error + 'static; + type Error: std::error::Error + Send + Sync + 'static; /// An iterator visiting all quads of this dataset in arbitrary order. /// @@ -346,7 +346,7 @@ pub type MdResult = std::result::Result::Mutation /// see also [`SetDataset`]. pub trait MutableDataset: Dataset { /// The error type that this dataset may raise during mutations. - type MutationError: Error + 'static; + type MutationError: std::error::Error + Send + Sync + 'static; /// Insert the given quad in this dataset. /// diff --git a/api/src/dataset/adapter.rs b/api/src/dataset/adapter.rs index 7c86783c..f4f01889 100644 --- a/api/src/dataset/adapter.rs +++ b/api/src/dataset/adapter.rs @@ -1,4 +1,6 @@ //! I define adapters for the [`dataset`](super) related traits. +use std::error::Error; + use super::*; use crate::graph::{GTerm, Graph, MutableGraph}; use crate::quad::Spog; diff --git a/api/src/graph.rs b/api/src/graph.rs index fb16dc91..47dca786 100644 --- a/api/src/graph.rs +++ b/api/src/graph.rs @@ -53,7 +53,7 @@ pub trait Graph { where Self: 'x; /// The error type that this graph may raise. - type Error: Error + 'static; + type Error: std::error::Error + Send + Sync + 'static; /// An iterator visiting all triples of this graph in arbitrary order. /// @@ -305,7 +305,7 @@ pub type MgResult = std::result::Result::MutationEr /// see also [`SetGraph`]. pub trait MutableGraph: Graph { /// The error type that this graph may raise during mutations. - type MutationError: Error + 'static; + type MutationError: std::error::Error + Send + Sync + 'static; /// Insert in this graph a triple made of the the given terms. /// diff --git a/api/src/lib.rs b/api/src/lib.rs index bed15ef0..4cf3d65d 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -66,5 +66,3 @@ pub mod triple; /// Re-export MownStr to avoid dependency version mismatch. /// pub use mownstr::MownStr; - -pub use sophia_iri::Error; diff --git a/api/src/source.rs b/api/src/source.rs index 97b25c2e..1ebb8bc1 100644 --- a/api/src/source.rs +++ b/api/src/source.rs @@ -56,8 +56,6 @@ //! [`for_each_quad`]: QuadSource::for_each_quad //! [higher-rank trait bounds]: https://doc.rust-lang.org/nomicon/hrtb.html - - pub mod convert; pub mod filter; pub mod filter_map; @@ -87,7 +85,7 @@ pub trait Source { /// The type of items this source yields. type Item<'x>; /// The type of errors produced by this source. - type Error: Error + 'static; + type Error: std::error::Error + Send + Sync + 'static; /// Call f for some item(s) (possibly zero) from this source, if any. /// @@ -96,7 +94,7 @@ pub trait Source { /// Return an error if either the source or `f` errs. fn try_for_some_item(&mut self, f: F) -> StreamResult where - E: Error, + E: std::error::Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), E>; /// Call f for all items from this source. @@ -106,7 +104,7 @@ pub trait Source { fn try_for_each_item(&mut self, mut f: F) -> StreamResult<(), Self::Error, E> where F: FnMut(Self::Item<'_>) -> Result<(), E>, - E: Error, + E: std::error::Error + Send + Sync + 'static, { while self.try_for_some_item(&mut f)? {} Ok(()) @@ -200,14 +198,14 @@ pub trait Source { impl<'a, I, T, E> Source for I where I: Iterator> + 'a, - E: Error + 'static, + E: std::error::Error + Send + Sync + 'static, { type Item<'x> = T; type Error = E; fn try_for_some_item(&mut self, mut f: F) -> StreamResult where - E2: Error, + E2: std::error::Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), E2>, { match self.next() { diff --git a/api/src/source/_quad.rs b/api/src/source/_quad.rs index 468a1486..bd347c6c 100644 --- a/api/src/source/_quad.rs +++ b/api/src/source/_quad.rs @@ -1,3 +1,5 @@ +use std::error::Error; + use super::*; use crate::dataset::{CollectibleDataset, Dataset, MutableDataset}; use crate::quad::Quad; @@ -20,7 +22,7 @@ pub trait QuadSource: Source + IsQuadSource { #[inline] fn try_for_some_quad(&mut self, mut f: F) -> StreamResult where - E: Error, + E: std::error::Error + Send + Sync + 'static, F: FnMut(Self::Quad<'_>) -> Result<(), E>, { self.try_for_some_item(|i| f(Self::i2q(i))) @@ -33,7 +35,7 @@ pub trait QuadSource: Source + IsQuadSource { fn try_for_each_quad(&mut self, mut f: F) -> StreamResult<(), Self::Error, E> where F: FnMut(Self::Quad<'_>) -> Result<(), E>, - E: Error, + E: std::error::Error + Send + Sync + 'static, { self.try_for_each_item(|i| f(Self::i2q(i))) } diff --git a/api/src/source/_stream_error.rs b/api/src/source/_stream_error.rs index 189f4b06..f738d922 100644 --- a/api/src/source/_stream_error.rs +++ b/api/src/source/_stream_error.rs @@ -1,5 +1,3 @@ - - /// A error that is raised by functions that move fallible `Source`s into /// fallible `Sinks`. /// @@ -24,6 +22,8 @@ where #[error("Sink failed: {0}")] SinkError(#[source] SinkErr), } +use std::error::Error; + pub use StreamError::*; impl StreamError diff --git a/api/src/source/_triple.rs b/api/src/source/_triple.rs index f90dedef..68541277 100644 --- a/api/src/source/_triple.rs +++ b/api/src/source/_triple.rs @@ -1,3 +1,5 @@ +use std::error::Error; + use super::*; use crate::graph::{CollectibleGraph, Graph, MutableGraph}; use crate::triple::Triple; @@ -20,7 +22,7 @@ pub trait TripleSource: Source + IsTripleSource { #[inline] fn try_for_some_triple(&mut self, mut f: F) -> StreamResult where - E: Error, + E: std::error::Error + Send + Sync + 'static, F: FnMut(TSTriple) -> Result<(), E>, { self.try_for_some_item(|i| f(Self::i2t(i))) @@ -33,7 +35,7 @@ pub trait TripleSource: Source + IsTripleSource { fn try_for_each_triple(&mut self, mut f: F) -> StreamResult<(), Self::Error, E> where F: FnMut(TSTriple) -> Result<(), E>, - E: Error, + E: std::error::Error + Send + Sync + 'static, { self.try_for_each_item(|i| f(Self::i2t(i))) } diff --git a/api/src/source/filter_map.rs b/api/src/source/filter_map.rs index d8057009..467e9f91 100644 --- a/api/src/source/filter_map.rs +++ b/api/src/source/filter_map.rs @@ -1,6 +1,6 @@ //! I define [`FilterMapSource`] the result type of [`Source::filter_map_items`]. use super::*; -use std::collections::VecDeque; +use std::{collections::VecDeque, error::Error}; /// The result of [`Source::filter_map_items`]. pub struct FilterMapSource { @@ -18,7 +18,7 @@ where fn try_for_some_item(&mut self, mut f: F2) -> StreamResult where - E: Error, + E: std::error::Error + Send + Sync + 'static, F2: FnMut(Self::Item<'_>) -> Result<(), E>, { let filter_map = &mut self.filter_map; diff --git a/api/src/source/map.rs b/api/src/source/map.rs index d6f21bfc..895666e9 100644 --- a/api/src/source/map.rs +++ b/api/src/source/map.rs @@ -1,6 +1,6 @@ //! I define [`MapSource`], the result type of [`Source::map_items`]. use super::*; -use std::collections::VecDeque; +use std::{collections::VecDeque, error::Error}; /// The result of [`Source::map_items`]. pub struct MapSource { @@ -18,7 +18,7 @@ where fn try_for_some_item(&mut self, mut f: F2) -> StreamResult where - E: Error, + E: std::error::Error + Send + Sync + 'static, F2: FnMut(Self::Item<'_>) -> Result<(), E>, { let map = &mut self.map; diff --git a/api/src/sparql.rs b/api/src/sparql.rs index 09374f45..12417831 100644 --- a/api/src/sparql.rs +++ b/api/src/sparql.rs @@ -41,7 +41,7 @@ pub trait SparqlDataset { /// The type of triples that GRAPH and DESCRIBE queries will return. type TriplesResult: TripleSource; /// The type of errors that processing SPARQL queries may raise. - type SparqlError: Error + 'static; + type SparqlError: std::error::Error + Send + Sync + 'static; /// The type representing pre-processed queries. /// /// See [`prepare_query`](#tymethod.prepare_query) for more detail. @@ -81,7 +81,7 @@ pub trait SparqlDataset { /// [`prepare_query`](SparqlDataset::prepare_query) method. pub trait Query: Sized { /// The error type that might be raised when parsing a query. - type Error: Error + 'static; + type Error: std::error::Error + Send + Sync + 'static; /// Parse the given text into a [`Query`]. fn parse(query_source: &str) -> Result; } diff --git a/inmem/src/index.rs b/inmem/src/index.rs index 0975f4a4..0ccd18c4 100644 --- a/inmem/src/index.rs +++ b/inmem/src/index.rs @@ -64,7 +64,7 @@ pub trait TermIndex { /// The type of [indices](Index) used by this [`TermIndex`] type Index: Index; /// The type of error that this [`TermIndex`] may raise - type Error: Error + 'static; + type Error: std::error::Error + Send + Sync + 'static; /// Get the index corresponding to term `t`, if it exists. /// diff --git a/iri/Cargo.toml b/iri/Cargo.toml index 2b1ebe2b..3d8f1794 100644 --- a/iri/Cargo.toml +++ b/iri/Cargo.toml @@ -27,7 +27,6 @@ criterion.workspace = true toml = "0.8.0" [features] -threadsafe_err = [] default = ["serde"] test_data = [] examples = [] diff --git a/iri/src/lib.rs b/iri/src/lib.rs index 1c81ed89..23d5a5ef 100644 --- a/iri/src/lib.rs +++ b/iri/src/lib.rs @@ -40,12 +40,3 @@ pub mod wrap_macro_examples; #[cfg(any(test, feature = "test_data"))] pub mod test; - -#[cfg(not(feature = "threadsafe_err"))] -pub use std::error::Error; -#[cfg(feature = "threadsafe_err")] -pub use ThreadSafeError as Error; - -/// An error trait meant to enable sending errors safely across threads. -pub trait ThreadSafeError: std::error::Error + Send + Sync + 'static {} -impl ThreadSafeError for E where E: std::error::Error + Send + Sync + 'static {} diff --git a/resource/src/resource/_error.rs b/resource/src/resource/_error.rs index c1ba1d65..681bc3a1 100644 --- a/resource/src/resource/_error.rs +++ b/resource/src/resource/_error.rs @@ -1,10 +1,11 @@ use sophia_api::term::TermKind; -use sophia_api::{prelude::*, term::SimpleTerm, Error}; +use sophia_api::{prelude::*, term::SimpleTerm}; +use std::error::Error; use std::fmt; /// An error raised when creating a [`Resource`](crate::Resource) #[derive(Debug)] -pub enum ResourceError { +pub enum ResourceError { /// The IRI is not absolute (an can therefore not be dereferenced) IriNotAbsolute(IriRef>), /// The resource could not be loaded @@ -69,7 +70,10 @@ pub enum ResourceError { }, } -impl ResourceError { +impl ResourceError +where + E: Error + Send + Sync + 'static, +{ /// The identifier of the resource raising the error. /// /// NB: for errors raised during creation ([`ResourceError::IriNotAbsolute`], [`ResourceError::LoaderError`]), @@ -90,19 +94,25 @@ impl ResourceError { } } -impl fmt::Display for ResourceError { +impl fmt::Display for ResourceError +where + E: Error + Send + Sync + 'static, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } } -impl From for ResourceError { +impl From for ResourceError +where + E: Error + Send + Sync + 'static, +{ fn from(value: crate::loader::LoaderError) -> Self { Self::LoaderError(value) } } -impl std::error::Error for ResourceError where E: std::error::Error + Send + Sync + 'static {} +impl Error for ResourceError where E: Error + Send + Sync + 'static {} /// A result whose error is a [`ResourceError`] pub type ResourceResult = Result::Error>>; diff --git a/rio/src/parser.rs b/rio/src/parser.rs index 64465938..7c23ccf4 100644 --- a/rio/src/parser.rs +++ b/rio/src/parser.rs @@ -6,10 +6,11 @@ //! published versions of Rio will always depend on the previously published version of Sophia, //! which makes it impossible for Sophia itself to rely on that feature. +use std::error::Error; + use crate::model::Trusted; use sophia_api::source::{StreamError, StreamError::*, StreamResult}; - /// Wrap a Rio [`TriplesParser`](rio_api::parser::TriplesParser) /// into a Sophia [`TripleSource`](sophia_api::source::TripleSource). pub struct StrictRioTripleSource(pub T); @@ -17,7 +18,7 @@ pub struct StrictRioTripleSource(pub T); impl sophia_api::source::Source for StrictRioTripleSource where T: rio_api::parser::TriplesParser, - T::Error: Error + 'static, + T::Error: Error + Send + Sync + 'static, { type Item<'x> = Trusted>; @@ -25,7 +26,7 @@ where fn try_for_some_item(&mut self, mut f: F) -> StreamResult where - EF: Error, + EF: Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), EF>, { let parser = &mut self.0; @@ -50,7 +51,7 @@ pub struct StrictRioQuadSource(pub T); impl sophia_api::source::Source for StrictRioQuadSource where T: rio_api::parser::QuadsParser, - T::Error: Error + 'static, + T::Error: Error + Send + Sync + 'static, { type Item<'x> = Trusted>; @@ -58,7 +59,7 @@ where fn try_for_some_item(&mut self, mut f: F) -> StreamResult where - EF: Error, + EF: Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), EF>, { let parser = &mut self.0; @@ -83,7 +84,7 @@ pub struct GeneralizedRioSource(pub T); impl sophia_api::source::Source for GeneralizedRioSource where T: rio_api::parser::GeneralizedQuadsParser, - T::Error: Error + 'static, + T::Error: Error + Send + Sync + 'static, { type Item<'x> = Trusted>; @@ -91,7 +92,7 @@ where fn try_for_some_item(&mut self, mut f: F) -> StreamResult where - EF: Error, + EF: Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), EF>, { let parser = &mut self.0; @@ -125,8 +126,8 @@ enum RioStreamError { } impl From for RioStreamError where - E1: Error, - E2: Error, + E1: Error + Send + Sync + 'static, + E2: Error + Send + Sync + 'static, { fn from(other: E1) -> Self { RioStreamError::Source(other) @@ -134,8 +135,8 @@ where } impl From> for StreamError where - E1: Error, - E2: Error, + E1: Error + Send + Sync + 'static, + E2: Error + Send + Sync + 'static, { fn from(other: RioStreamError) -> Self { match other { diff --git a/sophia/Cargo.toml b/sophia/Cargo.toml index 04ad39ae..6a27f7d3 100644 --- a/sophia/Cargo.toml +++ b/sophia/Cargo.toml @@ -25,7 +25,6 @@ test_macro = ["sophia_api/test_macro"] file_url = ["sophia_jsonld/file_url", "sophia_resource/file_url"] # This feature enables the HTTP client in dependencies http_client = ["sophia_jsonld/http_client", "sophia_resource/http_client"] -threadsafe_err = ["sophia_api/threadsafe_err"] [dependencies] sophia_iri.workspace = true From e30b824eae556621616f2597880252aa6c0ad8d0 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Fri, 26 Jul 2024 15:41:09 -0500 Subject: [PATCH 19/20] clippy lint --- api/src/source/_quad.rs | 4 ++-- api/src/source/_triple.rs | 4 ++-- api/src/source/filter_map.rs | 2 +- api/src/source/map.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/src/source/_quad.rs b/api/src/source/_quad.rs index bd347c6c..e5a48290 100644 --- a/api/src/source/_quad.rs +++ b/api/src/source/_quad.rs @@ -22,7 +22,7 @@ pub trait QuadSource: Source + IsQuadSource { #[inline] fn try_for_some_quad(&mut self, mut f: F) -> StreamResult where - E: std::error::Error + Send + Sync + 'static, + E: Error + Send + Sync + 'static, F: FnMut(Self::Quad<'_>) -> Result<(), E>, { self.try_for_some_item(|i| f(Self::i2q(i))) @@ -35,7 +35,7 @@ pub trait QuadSource: Source + IsQuadSource { fn try_for_each_quad(&mut self, mut f: F) -> StreamResult<(), Self::Error, E> where F: FnMut(Self::Quad<'_>) -> Result<(), E>, - E: std::error::Error + Send + Sync + 'static, + E: Error + Send + Sync + 'static, { self.try_for_each_item(|i| f(Self::i2q(i))) } diff --git a/api/src/source/_triple.rs b/api/src/source/_triple.rs index 68541277..0f80c192 100644 --- a/api/src/source/_triple.rs +++ b/api/src/source/_triple.rs @@ -22,7 +22,7 @@ pub trait TripleSource: Source + IsTripleSource { #[inline] fn try_for_some_triple(&mut self, mut f: F) -> StreamResult where - E: std::error::Error + Send + Sync + 'static, + E: Error + Send + Sync + 'static, F: FnMut(TSTriple) -> Result<(), E>, { self.try_for_some_item(|i| f(Self::i2t(i))) @@ -35,7 +35,7 @@ pub trait TripleSource: Source + IsTripleSource { fn try_for_each_triple(&mut self, mut f: F) -> StreamResult<(), Self::Error, E> where F: FnMut(TSTriple) -> Result<(), E>, - E: std::error::Error + Send + Sync + 'static, + E: Error + Send + Sync + 'static, { self.try_for_each_item(|i| f(Self::i2t(i))) } diff --git a/api/src/source/filter_map.rs b/api/src/source/filter_map.rs index 467e9f91..0f3a3e78 100644 --- a/api/src/source/filter_map.rs +++ b/api/src/source/filter_map.rs @@ -18,7 +18,7 @@ where fn try_for_some_item(&mut self, mut f: F2) -> StreamResult where - E: std::error::Error + Send + Sync + 'static, + E: Error + Send + Sync + 'static, F2: FnMut(Self::Item<'_>) -> Result<(), E>, { let filter_map = &mut self.filter_map; diff --git a/api/src/source/map.rs b/api/src/source/map.rs index 895666e9..9bdd3511 100644 --- a/api/src/source/map.rs +++ b/api/src/source/map.rs @@ -18,7 +18,7 @@ where fn try_for_some_item(&mut self, mut f: F2) -> StreamResult where - E: std::error::Error + Send + Sync + 'static, + E: Error + Send + Sync + 'static, F2: FnMut(Self::Item<'_>) -> Result<(), E>, { let map = &mut self.map; From 47805e10bacce143fd111c16d63431612a85ff59 Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Fri, 26 Jul 2024 15:45:40 -0500 Subject: [PATCH 20/20] revert explicit imports --- api/src/dataset.rs | 6 ++++-- api/src/graph.rs | 6 ++++-- api/src/source.rs | 12 ++++++------ api/src/sparql.rs | 5 +++-- inmem/src/index.rs | 3 ++- isomorphism/src/test.rs | 26 ++++++++++++++------------ turtle/src/serializer/trig.rs | 6 ++++-- turtle/src/serializer/turtle.rs | 6 ++++-- 8 files changed, 41 insertions(+), 29 deletions(-) diff --git a/api/src/dataset.rs b/api/src/dataset.rs index b1821c7b..ac7c9b80 100644 --- a/api/src/dataset.rs +++ b/api/src/dataset.rs @@ -7,6 +7,8 @@ //! for different kinds of datasets, //! as well as a few implementations for them. +use std::error::Error; + use crate::graph::adapter::{DatasetGraph, PartialUnionGraph, UnionGraph}; use crate::quad::{iter_spog, Quad}; use crate::source::{IntoSource, QuadSource, StreamResult}; @@ -56,7 +58,7 @@ pub trait Dataset { where Self: 'x; /// The error type that this dataset may raise. - type Error: std::error::Error + Send + Sync + 'static; + type Error: Error + Send + Sync + 'static; /// An iterator visiting all quads of this dataset in arbitrary order. /// @@ -346,7 +348,7 @@ pub type MdResult = std::result::Result::Mutation /// see also [`SetDataset`]. pub trait MutableDataset: Dataset { /// The error type that this dataset may raise during mutations. - type MutationError: std::error::Error + Send + Sync + 'static; + type MutationError: Error + Send + Sync + 'static; /// Insert the given quad in this dataset. /// diff --git a/api/src/graph.rs b/api/src/graph.rs index 47dca786..64755ee9 100644 --- a/api/src/graph.rs +++ b/api/src/graph.rs @@ -5,6 +5,8 @@ //! for different kinds of graph, //! as well as a few implementations for them. +use std::error::Error; + use crate::dataset::adapter::GraphAsDataset; use crate::source::{IntoSource, StreamResult, TripleSource}; use crate::term::{matcher::TermMatcher, SimpleTerm, Term}; @@ -53,7 +55,7 @@ pub trait Graph { where Self: 'x; /// The error type that this graph may raise. - type Error: std::error::Error + Send + Sync + 'static; + type Error: Error + Send + Sync + 'static; /// An iterator visiting all triples of this graph in arbitrary order. /// @@ -305,7 +307,7 @@ pub type MgResult = std::result::Result::MutationEr /// see also [`SetGraph`]. pub trait MutableGraph: Graph { /// The error type that this graph may raise during mutations. - type MutationError: std::error::Error + Send + Sync + 'static; + type MutationError: Error + Send + Sync + 'static; /// Insert in this graph a triple made of the the given terms. /// diff --git a/api/src/source.rs b/api/src/source.rs index 1ebb8bc1..44381e8d 100644 --- a/api/src/source.rs +++ b/api/src/source.rs @@ -68,7 +68,7 @@ pub use _stream_error::*; mod _triple; pub use _triple::*; -use std::convert::Infallible; +use std::{convert::Infallible, error::Error}; /// A source produces [items](Source::Item), and may also fail in the process. /// @@ -85,7 +85,7 @@ pub trait Source { /// The type of items this source yields. type Item<'x>; /// The type of errors produced by this source. - type Error: std::error::Error + Send + Sync + 'static; + type Error: Error + Send + Sync + 'static; /// Call f for some item(s) (possibly zero) from this source, if any. /// @@ -94,7 +94,7 @@ pub trait Source { /// Return an error if either the source or `f` errs. fn try_for_some_item(&mut self, f: F) -> StreamResult where - E: std::error::Error + Send + Sync + 'static, + E: Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), E>; /// Call f for all items from this source. @@ -104,7 +104,7 @@ pub trait Source { fn try_for_each_item(&mut self, mut f: F) -> StreamResult<(), Self::Error, E> where F: FnMut(Self::Item<'_>) -> Result<(), E>, - E: std::error::Error + Send + Sync + 'static, + E: Error + Send + Sync + 'static, { while self.try_for_some_item(&mut f)? {} Ok(()) @@ -198,14 +198,14 @@ pub trait Source { impl<'a, I, T, E> Source for I where I: Iterator> + 'a, - E: std::error::Error + Send + Sync + 'static, + E: Error + Send + Sync + 'static, { type Item<'x> = T; type Error = E; fn try_for_some_item(&mut self, mut f: F) -> StreamResult where - E2: std::error::Error + Send + Sync + 'static, + E2: Error + Send + Sync + 'static, F: FnMut(Self::Item<'_>) -> Result<(), E2>, { match self.next() { diff --git a/api/src/sparql.rs b/api/src/sparql.rs index 12417831..03baec51 100644 --- a/api/src/sparql.rs +++ b/api/src/sparql.rs @@ -31,6 +31,7 @@ use crate::source::TripleSource; use crate::term::Term; use std::borrow::Borrow; +use std::error::Error; /// A dataset that can be queried with SPARQL. pub trait SparqlDataset { @@ -41,7 +42,7 @@ pub trait SparqlDataset { /// The type of triples that GRAPH and DESCRIBE queries will return. type TriplesResult: TripleSource; /// The type of errors that processing SPARQL queries may raise. - type SparqlError: std::error::Error + Send + Sync + 'static; + type SparqlError: Error + Send + Sync + 'static; /// The type representing pre-processed queries. /// /// See [`prepare_query`](#tymethod.prepare_query) for more detail. @@ -81,7 +82,7 @@ pub trait SparqlDataset { /// [`prepare_query`](SparqlDataset::prepare_query) method. pub trait Query: Sized { /// The error type that might be raised when parsing a query. - type Error: std::error::Error + Send + Sync + 'static; + type Error: Error + Send + Sync + 'static; /// Parse the given text into a [`Query`]. fn parse(query_source: &str) -> Result; } diff --git a/inmem/src/index.rs b/inmem/src/index.rs index 0ccd18c4..c4092864 100644 --- a/inmem/src/index.rs +++ b/inmem/src/index.rs @@ -3,6 +3,7 @@ use sophia_api::term::{FromTerm, GraphName, SimpleTerm, Term}; use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::error::Error; /// Abstraction of the short numeric indices representing [terms](Term) in a [`TermIndex`]. pub trait Index: Copy + std::fmt::Debug + Ord { @@ -64,7 +65,7 @@ pub trait TermIndex { /// The type of [indices](Index) used by this [`TermIndex`] type Index: Index; /// The type of error that this [`TermIndex`] may raise - type Error: std::error::Error + Send + Sync + 'static; + type Error: Error + Send + Sync + 'static; /// Get the index corresponding to term `t`, if it exists. /// diff --git a/isomorphism/src/test.rs b/isomorphism/src/test.rs index b1130178..bec78767 100644 --- a/isomorphism/src/test.rs +++ b/isomorphism/src/test.rs @@ -1,3 +1,5 @@ +use std::error::Error; + use super::*; use sophia_api::ns::xsd; use sophia_api::term::{assert_consistent_term_impl, BnodeId, IriRef, Term, TermKind}; @@ -11,7 +13,7 @@ const LIT_ALICE: MyTerm = MyTerm::String("alice"); const LIT_BOB: MyTerm = MyTerm::String("bob"); #[test] -fn no_bnode() -> Result<(), Box> { +fn no_bnode() -> Result<(), Box> { let make_dataset = |i1: &'static str, i2: &'static str| -> Vec<([MyTerm; 3], Option)> { let i1 = MyTerm::Iri(i1); let i2 = MyTerm::Iri(i2); @@ -46,7 +48,7 @@ fn no_bnode() -> Result<(), Box> { } #[test] -fn simple() -> Result<(), Box> { +fn simple() -> Result<(), Box> { let make_dataset = |b1: &'static str, b2: &'static str| -> Vec<([MyTerm; 3], Option)> { let b1 = MyTerm::Bnode(b1); let b2 = MyTerm::Bnode(b2); @@ -82,7 +84,7 @@ fn simple() -> Result<(), Box> { } #[test] -fn no_bnode_quoted_triple() -> Result<(), Box> { +fn no_bnode_quoted_triple() -> Result<(), Box> { const A: MyTerm = MyTerm::Iri("#a"); const B: MyTerm = MyTerm::Iri("#b"); const C: MyTerm = MyTerm::Iri("#c"); @@ -114,7 +116,7 @@ fn no_bnode_quoted_triple() -> Result<(), Box> { } #[test] -fn quoted_triple() -> Result<(), Box> { +fn quoted_triple() -> Result<(), Box> { const A: MyTerm = MyTerm::Bnode("a"); const B: MyTerm = MyTerm::Bnode("b"); const C: MyTerm = MyTerm::Bnode("c"); @@ -158,7 +160,7 @@ fn make_chain(ids: &'static str) -> Vec<[MyTerm; 4]> { } #[test] -fn chain() -> Result<(), Box> { +fn chain() -> Result<(), Box> { let d1 = make_chain("abcdefghij"); assert!(isomorphic_datasets(&d1, &d1)?); let d2 = make_chain("EDCBAJIHGF"); @@ -171,7 +173,7 @@ fn chain() -> Result<(), Box> { } #[test] -fn cycle2() -> Result<(), Box> { +fn cycle2() -> Result<(), Box> { let d1 = make_chain("aba"); assert!(isomorphic_datasets(&d1, &d1)?); let d2 = make_chain("BAB"); @@ -181,7 +183,7 @@ fn cycle2() -> Result<(), Box> { } #[test] -fn cycle_long() -> Result<(), Box> { +fn cycle_long() -> Result<(), Box> { let d1 = make_chain("abcdefghia"); assert!(isomorphic_datasets(&d1, &d1)?); let d2 = make_chain("EBCDAIGHFE"); @@ -195,7 +197,7 @@ fn cycle_long() -> Result<(), Box> { #[test] #[ignore] -fn cycle_pathological() -> Result<(), Box> { +fn cycle_pathological() -> Result<(), Box> { // This case is tricky (and does not work with the current implementation). // Both graphs contain the same number of (blank nodes) and the same number of arcs. // All blank nodes are locally undistinguishable from each other: @@ -211,7 +213,7 @@ fn cycle_pathological() -> Result<(), Box> { } #[test] -fn cycle_almost_pathological() -> Result<(), Box> { +fn cycle_almost_pathological() -> Result<(), Box> { // This is uses the same graphs as above (cycle_pathological), // but *one* of the blank nodes is distinguished by an additional property, // which breaks symmetry and allow the algorithm to give the correct answer. @@ -247,7 +249,7 @@ fn make_clique(ids: &'static str) -> Vec<[MyTerm; 4]> { } #[test] -fn clique() -> Result<(), Box> { +fn clique() -> Result<(), Box> { let d1 = make_clique("abcde"); assert!(isomorphic_datasets(&d1, &d1)?); @@ -278,7 +280,7 @@ fn make_tree(ids: &'static str) -> Vec<[MyTerm; 4]> { } #[test] -fn tree() -> Result<(), Box> { +fn tree() -> Result<(), Box> { let d1 = make_tree("abcdefghij"); assert!(isomorphic_datasets(&d1, &d1)?); @@ -292,7 +294,7 @@ fn tree() -> Result<(), Box> { } #[test] -fn predicate_and_gname() -> Result<(), Box> { +fn predicate_and_gname() -> Result<(), Box> { let rel = MyTerm::Iri("tag:rel"); let b1 = MyTerm::Bnode("b1"); let b2 = MyTerm::Bnode("b2"); diff --git a/turtle/src/serializer/trig.rs b/turtle/src/serializer/trig.rs index 35f02f9b..2219f545 100644 --- a/turtle/src/serializer/trig.rs +++ b/turtle/src/serializer/trig.rs @@ -107,6 +107,8 @@ impl Stringifier for TrigSerializer> { #[cfg(test)] pub(crate) mod test { + use std::error::Error; + use super::*; use sophia_api::term::SimpleTerm; @@ -177,7 +179,7 @@ pub(crate) mod test { ]; #[test] - fn roundtrip_not_pretty() -> Result<(), Box> { + fn roundtrip_not_pretty() -> Result<(), Box> { for ttl in TESTS { println!("==========\n{}\n----------", ttl); let g1: Vec> = crate::parser::trig::parse_str(ttl).collect_quads()?; @@ -195,7 +197,7 @@ pub(crate) mod test { } #[test] - fn roundtrip_pretty() -> Result<(), Box> { + fn roundtrip_pretty() -> Result<(), Box> { for ttl in TESTS { println!("==========\n{}\n----------", ttl); let g1: Vec> = crate::parser::trig::parse_str(ttl).collect_quads()?; diff --git a/turtle/src/serializer/turtle.rs b/turtle/src/serializer/turtle.rs index 37d70d3e..514aa58b 100644 --- a/turtle/src/serializer/turtle.rs +++ b/turtle/src/serializer/turtle.rs @@ -209,6 +209,8 @@ impl Stringifier for TurtleSerializer> { #[cfg(test)] pub(crate) mod test { + use std::error::Error; + use super::*; use sophia_api::graph::Graph; use sophia_isomorphism::isomorphic_graphs; @@ -245,7 +247,7 @@ pub(crate) mod test { ]; #[test] - fn roundtrip_not_pretty() -> Result<(), Box> { + fn roundtrip_not_pretty() -> Result<(), Box> { for ttl in TESTS { println!("==========\n{}\n----------", ttl); let g1: Vec<[SimpleTerm; 3]> = @@ -265,7 +267,7 @@ pub(crate) mod test { } #[test] - fn roundtrip_pretty() -> Result<(), Box> { + fn roundtrip_pretty() -> Result<(), Box> { for ttl in TESTS { println!("==========\n{}\n----------", ttl); let g1: Vec<[SimpleTerm; 3]> =