From b14fa780667bbd38ae0e3dd8a0ad64dddd8ef809 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 19 Oct 2023 13:42:35 -0400 Subject: [PATCH] feat: Extend error type to Send + Sync (#136) --- examples/caching_dependency_provider.rs | 4 ++-- src/error.rs | 6 +++--- src/lib.rs | 4 ++-- src/solver.rs | 10 +++++----- tests/proptest.rs | 18 +++++++++++++----- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/examples/caching_dependency_provider.rs b/examples/caching_dependency_provider.rs index cb278942..bec7d2ab 100644 --- a/examples/caching_dependency_provider.rs +++ b/examples/caching_dependency_provider.rs @@ -35,7 +35,7 @@ impl> DependencyProvid fn choose_package_version, U: std::borrow::Borrow>( &self, packages: impl Iterator, - ) -> Result<(T, Option), Box> { + ) -> Result<(T, Option), Box> { self.remote_dependencies.choose_package_version(packages) } @@ -44,7 +44,7 @@ impl> DependencyProvid &self, package: &P, version: &VS::V, - ) -> Result, Box> { + ) -> Result, Box> { let mut cache = self.cached_dependencies.borrow_mut(); match cache.get_dependencies(package, version) { Ok(Dependencies::Unknown) => { diff --git a/src/error.rs b/src/error.rs index 1098706c..b0633022 100644 --- a/src/error.rs +++ b/src/error.rs @@ -27,7 +27,7 @@ pub enum PubGrubError { version: VS::V, /// Error raised by the implementer of /// [DependencyProvider](crate::solver::DependencyProvider). - source: Box, + source: Box, }, /// Error arising when the implementer of @@ -63,12 +63,12 @@ pub enum PubGrubError { /// returned an error in the method /// [choose_package_version](crate::solver::DependencyProvider::choose_package_version). #[error("Decision making failed")] - ErrorChoosingPackageVersion(Box), + ErrorChoosingPackageVersion(Box), /// Error arising when the implementer of [DependencyProvider](crate::solver::DependencyProvider) /// returned an error in the method [should_cancel](crate::solver::DependencyProvider::should_cancel). #[error("We should cancel")] - ErrorInShouldCancel(Box), + ErrorInShouldCancel(Box), /// Something unexpected happened. #[error("{0}")] diff --git a/src/lib.rs b/src/lib.rs index 86debdcb..3934b8f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,7 +89,7 @@ //! type SemVS = Range; //! //! impl DependencyProvider for MyDependencyProvider { -//! fn choose_package_version, U: Borrow>(&self,packages: impl Iterator) -> Result<(T, Option), Box> { +//! fn choose_package_version, U: Borrow>(&self,packages: impl Iterator) -> Result<(T, Option), Box> { //! unimplemented!() //! } //! @@ -97,7 +97,7 @@ //! &self, //! package: &String, //! version: &SemanticVersion, -//! ) -> Result, Box> { +//! ) -> Result, Box> { //! unimplemented!() //! } //! } diff --git a/src/solver.rs b/src/solver.rs index 3962f3d5..a38d2871 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -259,7 +259,7 @@ pub trait DependencyProvider { fn choose_package_version, U: Borrow>( &self, potential_packages: impl Iterator, - ) -> Result<(T, Option), Box>; + ) -> Result<(T, Option), Box>; /// Retrieves the package dependencies. /// Return [Dependencies::Unknown] if its dependencies are unknown. @@ -267,14 +267,14 @@ pub trait DependencyProvider { &self, package: &P, version: &VS::V, - ) -> Result, Box>; + ) -> Result, Box>; /// This is called fairly regularly during the resolution, /// if it returns an Err then resolution will be terminated. /// This is helpful if you want to add some form of early termination like a timeout, /// or you want to add some form of user feedback if things are taking a while. /// If not provided the resolver will run as long as needed. - fn should_cancel(&self) -> Result<(), Box> { + fn should_cancel(&self) -> Result<(), Box> { Ok(()) } } @@ -384,7 +384,7 @@ impl DependencyProvider for OfflineDependency fn choose_package_version, U: Borrow>( &self, potential_packages: impl Iterator, - ) -> Result<(T, Option), Box> { + ) -> Result<(T, Option), Box> { Ok(choose_package_with_fewest_versions( |p| { self.dependencies @@ -402,7 +402,7 @@ impl DependencyProvider for OfflineDependency &self, package: &P, version: &VS::V, - ) -> Result, Box> { + ) -> Result, Box> { Ok(match self.dependencies(package, version) { None => Dependencies::Unknown, Some(dependencies) => Dependencies::Known(dependencies), diff --git a/tests/proptest.rs b/tests/proptest.rs index 34c84c97..cb66d3e6 100644 --- a/tests/proptest.rs +++ b/tests/proptest.rs @@ -35,14 +35,18 @@ impl DependencyProvider fn choose_package_version, U: std::borrow::Borrow>( &self, potential_packages: impl Iterator, - ) -> Result<(T, Option), Box> { + ) -> Result<(T, Option), Box> { Ok(choose_package_with_fewest_versions( |p| self.0.versions(p).into_iter().flatten().cloned(), potential_packages, )) } - fn get_dependencies(&self, p: &P, v: &VS::V) -> Result, Box> { + fn get_dependencies( + &self, + p: &P, + v: &VS::V, + ) -> Result, Box> { self.0.get_dependencies(p, v) } } @@ -73,15 +77,19 @@ impl> DependencyProvid fn choose_package_version, U: std::borrow::Borrow>( &self, potential_packages: impl Iterator, - ) -> Result<(T, Option), Box> { + ) -> Result<(T, Option), Box> { self.dp.choose_package_version(potential_packages) } - fn get_dependencies(&self, p: &P, v: &VS::V) -> Result, Box> { + fn get_dependencies( + &self, + p: &P, + v: &VS::V, + ) -> Result, Box> { self.dp.get_dependencies(p, v) } - fn should_cancel(&self) -> Result<(), Box> { + fn should_cancel(&self) -> Result<(), Box> { assert!(self.start_time.elapsed().as_secs() < 60); let calls = self.call_count.get(); assert!(calls < self.max_calls);