Skip to content

Commit

Permalink
fix: clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Oct 22, 2024
1 parent 203e625 commit 7d4426d
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ jobs:
- name: Fmt
run: cargo fmt
- name: Clippy
run: cargo clippy --all --all-features
run: cargo clippy --workspace --all-features
check-nightly:
name: Check (nightly)
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions crates/api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum Error {

/// [geojson::Error]
#[error(transparent)]
GeoJson(#[from] geojson::Error),
GeoJson(#[from] Box<geojson::Error>),

/// An empty datetime interval.
#[error("empty datetime interval")]
Expand Down Expand Up @@ -77,7 +77,7 @@ pub enum Error {

/// A search has both bbox and intersects.
#[error("search has bbox and intersects")]
SearchHasBboxAndIntersects(Search),
SearchHasBboxAndIntersects(Box<Search>),

/// [serde_json::Error]
#[error(transparent)]
Expand Down
4 changes: 2 additions & 2 deletions crates/api/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Search {
pub fn valid(mut self) -> Result<Search> {
self.items = self.items.valid()?;
if self.items.bbox.is_some() & self.intersects.is_some() {
Err(Error::SearchHasBboxAndIntersects(self.clone()))
Err(Error::SearchHasBboxAndIntersects(Box::new(self.clone())))
} else {
Ok(self)
}
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Search {
if let Some(intersects) = self.intersects.clone() {
#[cfg(feature = "geo")]
{
let intersects: geo::Geometry = intersects.try_into()?;
let intersects: geo::Geometry = intersects.try_into().map_err(Box::new)?;
item.intersects(&intersects).map_err(Error::from)
}
#[cfg(not(feature = "geo"))]
Expand Down
12 changes: 7 additions & 5 deletions crates/cli/src/args/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ impl Run for Args {
let _ = join_set.spawn(async move { args.run(input, sender).await });
}
while let Some(result) = join_set.join_next().await {
if let Some(Value::Stac(stac::Value::Item(item))) = result?? {
if let Some(ref stream) = stream {
stream.send(stac::Value::Item(item).into()).await?;
} else {
items.push(item);
if let Some(Value::Stac(value)) = result?? {
if let stac::Value::Item(item) = *value {
if let Some(ref stream) = stream {
stream.send(stac::Value::Item(item).into()).await?;
} else {
items.push(item);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use stac::{IntoGeoparquet, ToNdjson};
#[serde(untagged)]
pub enum Value {
/// A STAC value.
Stac(stac::Value),
Stac(Box<stac::Value>),

/// A JSON value.
Json(serde_json::Value),
}

impl From<stac::Value> for Value {
fn from(value: stac::Value) -> Self {
Value::Stac(value)
Value::Stac(Box::new(value))
}
}

Expand All @@ -35,7 +35,7 @@ impl TryFrom<Value> for stac::Value {
type Error = Error;
fn try_from(value: Value) -> Result<Self> {
match value {
Value::Stac(value) => Ok(value),
Value::Stac(value) => Ok(*value),
Value::Json(value) => serde_json::from_value(value).map_err(Error::from),
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum Error {

/// [geojson::Error]
#[error(transparent)]
Geojson(#[from] geojson::Error),
Geojson(#[from] Box<geojson::Error>),

/// [std::io::Error]
#[error(transparent)]
Expand Down Expand Up @@ -111,15 +111,15 @@ pub enum Error {

/// This value is not an item.
#[error("value is not an item")]
NotAnItem(Value),
NotAnItem(Box<Value>),

/// This value is not a catalog.
#[error("value is not a catalog")]
NotACatalog(Value),
NotACatalog(Box<Value>),

/// This value is not a collection.
#[error("value is not a collection")]
NotACollection(Value),
NotACollection(Box<Value>),

/// This value is not an object.
#[error("not an object")]
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl Item {
T: geo::Intersects<geo::Geometry>,
{
if let Some(geometry) = self.geometry.clone() {
let geometry: geo::Geometry = geometry.try_into()?;
let geometry: geo::Geometry = geometry.try_into().map_err(Box::new)?;
Ok(intersects.intersects(&geometry))
} else {
Ok(false)
Expand Down Expand Up @@ -456,7 +456,7 @@ impl Item {
use geo::Intersects;

if let Some(geometry) = self.geometry.clone() {
let geometry: geo::Geometry = geometry.try_into()?;
let geometry: geo::Geometry = geometry.try_into().map_err(Box::new)?;
Ok(geometry.intersects(&bbox))
} else {
Ok(false)
Expand Down
2 changes: 1 addition & 1 deletion python/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(unused_crate_dependencies)]
#![deny(unused_crate_dependencies, warnings)]

mod error;
mod migrate;
Expand Down
6 changes: 3 additions & 3 deletions python/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use tokio::runtime::Builder;

#[pyfunction]
#[pyo3(signature = (href, *, format=None, options=None))]
pub fn read<'py>(
py: Python<'py>,
pub fn read(
py: Python<'_>,
href: String,
format: Option<String>,
options: Option<Vec<(String, String)>>,
) -> PyResult<Bound<'py, PyDict>> {
) -> PyResult<Bound<'_, PyDict>> {
let format = format
.and_then(|f| f.parse::<Format>().ok())
.or_else(|| Format::infer_from_href(&href))
Expand Down
11 changes: 7 additions & 4 deletions python/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use tokio::runtime::Builder;

#[pyfunction]
#[pyo3(signature = (href, *, intersects=None, ids=None, collections=None, max_items=None, limit=None, bbox=None, datetime=None, include=None, exclude=None, sortby=None, filter=None, query=None, use_duckdb=None))]
pub fn search<'py>(
py: Python<'py>,
#[allow(clippy::too_many_arguments)]
pub fn search(
py: Python<'_>,
href: String,
intersects: Option<StringOrDict>,
ids: Option<StringOrList>,
Expand All @@ -28,7 +29,7 @@ pub fn search<'py>(
filter: Option<StringOrDict>,
query: Option<Py<PyDict>>,
use_duckdb: Option<bool>,
) -> PyResult<Bound<'py, PyList>> {
) -> PyResult<Bound<'_, PyList>> {
let items = search_items(
href,
intersects,
Expand All @@ -52,6 +53,7 @@ pub fn search<'py>(

#[pyfunction]
#[pyo3(signature = (outfile, href, *, intersects=None, ids=None, collections=None, max_items=None, limit=None, bbox=None, datetime=None, include=None, exclude=None, sortby=None, filter=None, query=None, format=None, options=None, use_duckdb=None))]
#[allow(clippy::too_many_arguments)]
pub fn search_to(
outfile: String,
href: String,
Expand Down Expand Up @@ -106,6 +108,7 @@ pub fn search_to(
Ok(count)
}

#[allow(clippy::too_many_arguments)]
fn search_items(
href: String,
intersects: Option<StringOrDict>,
Expand Down Expand Up @@ -207,7 +210,7 @@ impl StringOrDict {
match self {
Self::String(s) => s.parse().map_err(Error::from).map_err(PyErr::from),
Self::Dict(dict) => {
Python::with_gil(|py| pythonize::depythonize(&dict.bind(py))).map_err(PyErr::from)
Python::with_gil(|py| pythonize::depythonize(dict.bind(py))).map_err(PyErr::from)
}
}
}
Expand Down

0 comments on commit 7d4426d

Please sign in to comment.