Skip to content

Commit 79815eb

Browse files
committed
Set up linting and format checking in CI
For now, this has to use the nightly version of Cargo/rustfmt, because I really want to preserve the multiple newlines between sections of code, and that requires the `blank_lines_upper_bound` configuration option in `.rustfmt.toml`. See rust-lang/rustfmt#3381 for the bug tracking the stabilization of this configuration option.
1 parent 7d741f3 commit 79815eb

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

.circleci/config.yml

+28-11
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ version: 2.1
22

33

44
commands:
5-
build_and_test_steps:
6-
description: "Build the library and test it"
5+
install_system_dependencies:
6+
description: "Install system-level libraries/tools we depend on"
77
steps:
8-
- checkout
98
- run:
109
name: Install system dependencies
1110
command: |
@@ -19,6 +18,11 @@ commands:
1918
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
2019
;;
2120
esac
21+
build_and_test_steps:
22+
description: "Build the library and test it"
23+
steps:
24+
- checkout
25+
- install_system_dependencies
2226
- run:
2327
name: Show environment info
2428
command: |
@@ -50,29 +54,42 @@ linux_job_config: &linux_job_config
5054

5155

5256
jobs:
53-
linux-msrv:
57+
test-linux-msrv:
5458
docker:
5559
- image: rust:1.56-slim
5660
<<: *linux_job_config
57-
linux-stable:
61+
test-linux-stable:
5862
docker:
5963
- image: rust:slim
6064
<<: *linux_job_config
61-
linux-nightly:
65+
test-linux-nightly:
6266
docker:
6367
- image: rustlang/rust:nightly-slim
6468
<<: *linux_job_config
65-
osx-stable:
69+
test-osx-stable:
6670
macos:
6771
xcode: "14.0.0"
6872
steps:
6973
- build_and_test_steps
74+
lint-and-format:
75+
docker:
76+
- image: rustlang/rust:nightly-slim
77+
steps:
78+
- checkout
79+
- install_system_dependencies
80+
- run:
81+
name: Run linter
82+
command: cargo +nightly clippy
83+
- run:
84+
name: Check formatting
85+
command: cargo +nightly fmt --check
7086

7187

7288
workflows:
7389
build-and-test:
7490
jobs:
75-
- linux-msrv
76-
- linux-stable
77-
- linux-nightly
78-
- osx-stable
91+
- test-linux-msrv
92+
- test-linux-stable
93+
- test-linux-nightly
94+
- test-osx-stable
95+
- lint-and-format

src/lib.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// You should have received a copy of the GNU General Public License
1414
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1515

16+
#![allow(clippy::needless_doctest_main)]
17+
1618
//! This library provides a Rust wrapper around the [gexiv2][gexiv2] library,
1719
//! which is itself a GObject-based wrapper around the [Exiv2][exiv2] library,
1820
//! which provides read and write access to the Exif, XMP, and IPTC metadata
@@ -47,7 +49,7 @@ use std::str;
4749
use std::os::unix::ffi::OsStrExt;
4850

4951
/// A wrapper type for the kinds of errors one might encounter when using the library.
50-
#[derive(Debug, PartialEq)]
52+
#[derive(Debug, PartialEq, Eq)]
5153
pub enum Rexiv2Error {
5254
/// No value found
5355
NoValue,
@@ -90,13 +92,13 @@ impl From<str::Utf8Error> for Rexiv2Error {
9092
pub type Result<T> = std::result::Result<T, Rexiv2Error>;
9193

9294
/// An opaque structure that serves as a container for a media file's metadata.
93-
#[derive(Debug, PartialEq)]
95+
#[derive(Debug, PartialEq, Eq)]
9496
pub struct Metadata {
9597
raw: *mut gexiv2::GExiv2Metadata,
9698
}
9799

98100
/// An opaque structure that serves as a container for a preview image.
99-
#[derive(Debug, PartialEq)]
101+
#[derive(Debug, PartialEq, Eq)]
100102
pub struct PreviewImage<'a> {
101103
raw: *mut gexiv2::GExiv2PreviewProperties,
102104
metadata: &'a Metadata, // Parent metadata to load a PreviewImage from a PreviewProperties.
@@ -111,7 +113,7 @@ pub struct GpsInfo {
111113
}
112114

113115
/// The possible data types that a tag can have.
114-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
116+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
115117
pub enum TagType {
116118
/// Exif BYTE type, 8-bit unsigned integer.
117119
UnsignedByte,
@@ -773,10 +775,7 @@ impl Metadata {
773775
let mut n = 0;
774776
while !(*ptr.offset(n)).is_null() {
775777
let preview_prop = *ptr.offset(n);
776-
previews.push(PreviewImage {
777-
raw: preview_prop,
778-
metadata: self,
779-
});
778+
previews.push(PreviewImage { raw: preview_prop, metadata: self });
780779
n += 1;
781780
}
782781
Some(previews)
@@ -792,11 +791,7 @@ impl Metadata {
792791
let alt = &mut 0.0;
793792
match unsafe { gexiv2::gexiv2_metadata_get_gps_info(self.raw, lon, lat, alt) } {
794793
0 => None,
795-
_ => Some(GpsInfo {
796-
longitude: *lon,
797-
latitude: *lat,
798-
altitude: *alt,
799-
}),
794+
_ => Some(GpsInfo { longitude: *lon, latitude: *lat, altitude: *alt }),
800795
}
801796
}
802797

tst/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn supports_bmff() {
9393
// after gexiv2 has been initialized (and the underlying libraries are the
9494
// right version gexiv2 v0.13.0/Exiv2 v0.27.4)
9595
if unsafe { gexiv2::gexiv2_get_version() } < 1300 {
96-
return;
96+
return;
9797
}
9898

9999
let meta = rexiv2::Metadata::new_from_buffer(include_bytes!("sample.HEIC")).unwrap();

0 commit comments

Comments
 (0)