Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove PartialEq from GdalError #286

Merged
merged 3 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- Implemented wrapper for `OGR_L_SetFeature`

- <https://github.com/georust/gdal/pull/264>

- Add `programs::raster::build_vrt`
- Add `GeoTransformEx` extension trait with `apply` and `invert`

Expand Down Expand Up @@ -47,7 +47,7 @@

- <https://github.com/georust/gdal/pull/273>

- Add `gdal::srs::CoordTransform::transform_bounds` as wrapper for `OCTTransformBounds` for GDAL 3.4
- Add `gdal::srs::CoordTransform::transform_bounds` as wrapper for `OCTTransformBounds` for GDAL 3.4

- <https://github.com/georust/gdal/pull/272>

Expand All @@ -59,6 +59,10 @@

- <https://github.com/georust/gdal/pull/265>

- Remove `PartialEq` from `GdalError`

- <https://github.com/georust/gdal/pull/286>

## 0.12

- Bump Rust edition to 2021
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use gdal_sys::{CPLErr, OGRErr, OGRFieldType, OGRwkbGeometryType};

pub type Result<T> = std::result::Result<T, GdalError>;

#[derive(Clone, PartialEq, Debug, Error)]
#[derive(Clone, Debug, Error)]
pub enum GdalError {
#[error("FfiNulError")]
FfiNulError(#[from] std::ffi::NulError),
Expand Down
2 changes: 1 addition & 1 deletion src/raster/rasterband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl<T: GdalType> Buffer<T> {
pub type ByteBuffer = Buffer<u8>;

/// Represents a color interpretation of a RasterBand
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum ColorInterpretation {
/// Undefined
Undefined,
Expand Down
18 changes: 9 additions & 9 deletions src/raster/rasterize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,21 @@ mod tests {
fn test_rasterizeoptions_as_ptr() {
let c_options = CslStringList::try_from(RasterizeOptions::default()).unwrap();
assert_eq!(
c_options.fetch_name_value("ALL_TOUCHED"),
Ok(Some("FALSE".to_string()))
c_options.fetch_name_value("ALL_TOUCHED").unwrap(),
Some("FALSE".to_string())
);
assert_eq!(c_options.fetch_name_value("BURN_VALUE_FROM"), Ok(None));
assert_eq!(c_options.fetch_name_value("BURN_VALUE_FROM").unwrap(), None);
assert_eq!(
c_options.fetch_name_value("MERGE_ALG"),
Ok(Some("REPLACE".to_string()))
c_options.fetch_name_value("MERGE_ALG").unwrap(),
Some("REPLACE".to_string())
);
assert_eq!(
c_options.fetch_name_value("CHUNKYSIZE"),
Ok(Some("0".to_string()))
c_options.fetch_name_value("CHUNKYSIZE").unwrap(),
Some("0".to_string())
);
assert_eq!(
c_options.fetch_name_value("OPTIM"),
Ok(Some("AUTO".to_string()))
c_options.fetch_name_value("OPTIM").unwrap(),
Some("AUTO".to_string())
);
}
}
Expand Down
58 changes: 30 additions & 28 deletions src/vector/vector_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,14 @@ mod tests {
assert_eq!(feature.field_as_integer64_by_name("railway").unwrap(), None);
assert_eq!(feature.field_as_double_by_name("railway").unwrap(), None);

// test error
assert_eq!(
feature.field_as_string_by_name("not_a_field"),
Err(GdalError::InvalidFieldName {
field_name: "not_a_field".to_owned(),
assert!(matches!(
feature.field_as_string_by_name("not_a_field").unwrap_err(),
GdalError::InvalidFieldName {
field_name,
method_name: "OGR_F_GetFieldIndex",
})
);
}
if field_name == "not_a_field"
));
});
}

Expand Down Expand Up @@ -371,13 +371,13 @@ mod tests {
assert_eq!(feature.field_as_double(railway_field).unwrap(), None);

// test error
assert_eq!(
feature.field_as_string(23),
Err(GdalError::InvalidFieldIndex {
assert!(matches!(
feature.field_as_string(23).unwrap_err(),
GdalError::InvalidFieldIndex {
index: 23,
method_name: "field_as_string",
})
);
}
));
});
}

Expand Down Expand Up @@ -415,20 +415,22 @@ mod tests {
assert_eq!(feature.field_as_datetime(railway_field).unwrap(), None);

// test error
assert_eq!(
feature.field_as_datetime_by_name("not_a_field"),
Err(GdalError::InvalidFieldName {
field_name: "not_a_field".to_owned(),
assert!(matches!(
feature
.field_as_datetime_by_name("not_a_field")
.unwrap_err(),
GdalError::InvalidFieldName {
field_name,
method_name: "OGR_F_GetFieldIndex",
})
);
assert_eq!(
feature.field_as_datetime(23),
Err(GdalError::InvalidFieldIndex {
} if field_name == "not_a_field"
));
assert!(matches!(
feature.field_as_datetime(23).unwrap_err(),
GdalError::InvalidFieldIndex {
index: 23,
method_name: "field_as_datetime",
})
);
}
));
});
}

Expand Down Expand Up @@ -849,13 +851,13 @@ mod tests {
assert_eq!(layer.features().count(), 21);

// force error
assert_eq!(
layer.set_attribute_filter("foo = bar"),
Err(GdalError::OgrError {
assert!(matches!(
layer.set_attribute_filter("foo = bar").unwrap_err(),
GdalError::OgrError {
err: gdal_sys::OGRErr::OGRERR_CORRUPT_DATA,
method_name: "OGR_L_SetAttributeFilter",
})
);
}
));
});
}

Expand Down
54 changes: 29 additions & 25 deletions src/vsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ mod tests {
assert_eq!(bytes, vec![1_u8, 2, 3, 4]);

// mem file must not be there anymore
assert_eq!(
unlink_mem_file(file_name),
Err(GdalError::UnlinkMemFile {
file_name: file_name.to_string()
})
);
assert!(matches!(
unlink_mem_file(file_name).unwrap_err(),
GdalError::UnlinkMemFile {
file_name
}
if file_name == file_name
));
}

#[test]
Expand Down Expand Up @@ -246,13 +247,14 @@ mod tests {

#[test]
fn no_mem_file() {
assert_eq!(
get_vsi_mem_file_bytes_owned("foobar"),
Err(GdalError::NullPointer {
assert!(matches!(
get_vsi_mem_file_bytes_owned("foobar").unwrap_err(),
GdalError::NullPointer {
method_name: "VSIGetMemFileBuffer",
msg: "".to_string(),
})
);
msg,
}
if msg.is_empty()
));
}

#[test]
Expand Down Expand Up @@ -286,20 +288,22 @@ mod tests {
fn unable_to_create() {
let file_name = "";

assert_eq!(
create_mem_file(file_name, vec![1_u8, 2, 3, 4]),
Err(GdalError::NullPointer {
assert!(matches!(
create_mem_file(file_name, vec![1_u8, 2, 3, 4]).unwrap_err(),
GdalError::NullPointer {
method_name: "VSIGetMemFileBuffer",
msg: "".to_string(),
})
);

assert_eq!(
unlink_mem_file(file_name),
Err(GdalError::UnlinkMemFile {
file_name: "".to_string()
})
);
msg,
}
if msg.is_empty()
));

assert!(matches!(
unlink_mem_file(file_name).unwrap_err(),
GdalError::UnlinkMemFile {
file_name,
}
if file_name.is_empty()
));
}

#[test]
Expand Down