Skip to content

Commit

Permalink
Merge branch 'knox/downstream' into feat/send-sync-error-traits
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev committed Jul 25, 2024
2 parents bd10212 + 6456ab6 commit e743625
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion resource/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod test {
pub const F5_LEN: usize = 20;

pub type MyGraph = Vec<[SimpleTerm<'static>; 3]>;
pub type TestResult = Result<(), Box<dyn std::error::Error>>;
pub type TestResult = Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>;

pub fn make_loader() -> LocalLoader {
let ns = NS.map_unchecked(MownStr::from);
Expand Down
2 changes: 1 addition & 1 deletion resource/src/loader/_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>),
ParseError(IriBuf, Box<dyn std::error::Error + Send + Sync + 'static>),
}

impl LoaderError {
Expand Down
13 changes: 8 additions & 5 deletions resource/src/resource/_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fmt;

/// An error raised when creating a [`Resource`](crate::Resource)
#[derive(Debug)]
pub enum ResourceError<E: Error> {
pub enum ResourceError<E: Error + Send + Sync + 'static> {
/// The IRI is not absolute (an can therefore not be dereferenced)
IriNotAbsolute(IriRef<Box<str>>),
/// The resource could not be loaded
Expand Down Expand Up @@ -70,7 +70,10 @@ pub enum ResourceError<E: Error> {
},
}

impl<E: Error> ResourceError<E> {
impl<E: Error + Send + Sync + 'static> ResourceError<E>
where
Self: Send + Sync + 'static,
{
/// The identifier of the resource raising the error.
///
/// NB: for errors raised during creation ([`ResourceError::IriNotAbsolute`], [`ResourceError::LoaderError`]),
Expand All @@ -91,19 +94,19 @@ impl<E: Error> ResourceError<E> {
}
}

impl<E: Error> fmt::Display for ResourceError<E> {
impl<E: Error + Send + Sync + 'static> fmt::Display for ResourceError<E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

impl<E: Error> From<crate::loader::LoaderError> for ResourceError<E> {
impl<E: Error + Send + Sync + 'static> From<crate::loader::LoaderError> for ResourceError<E> {
fn from(value: crate::loader::LoaderError) -> Self {
Self::LoaderError(value)
}
}

impl<E: Error> Error for ResourceError<E> {}
impl<E: Error + Send + Sync + 'static> Error for ResourceError<E> where Self: Send + Sync + 'static {}

/// A result whose error is a [`ResourceError`]
pub type ResourceResult<T, G> = Result<T, ResourceError<<G as Graph>::Error>>;
1 change: 1 addition & 0 deletions resource/src/resource/_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Resource<G, L> {
impl<G, L> Resource<G, L>
where
G: Graph + 'static,
G::Error: Send + Sync + 'static,
L: Loader,
{
/// Constructor
Expand Down
4 changes: 3 additions & 1 deletion resource/src/resource/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ fn no_reload() -> TestResult {
Ok(())
}

fn make_rsc(iri: Iri<&str>) -> Result<Resource<MyGraph, LocalLoader>, Box<dyn std::error::Error>> {
fn make_rsc(
iri: Iri<&str>,
) -> Result<Resource<MyGraph, LocalLoader>, Box<dyn std::error::Error + Send + Sync + 'static>> {
Ok(make_loader().arced().get_resource(iri)?)
}

0 comments on commit e743625

Please sign in to comment.