Skip to content

Commit 7e99081

Browse files
committed
Update rustfmt config and apply
1 parent dea85fb commit 7e99081

File tree

4 files changed

+109
-81
lines changed

4 files changed

+109
-81
lines changed

.rustfmt.toml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
fn_call_width = 80
2-
fn_args_layout = "Block"
3-
fn_arg_indent = "Tabbed"
4-
struct_lit_width = 80
5-
struct_variant_width = 80
6-
reorder_imported_names = true
7-
normalize_comments = true
8-
condense_wildcard_suffices = true
9-
take_source_hints = false
10-
write_mode = "Replace"
1+
blank_lines_upper_bound = 2
2+
struct_lit_width = 50

examples/timestamp.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ fn main() {
77
if let Ok(time) = meta.get_tag_string("Exif.Image.DateTime") {
88
println!("Time: {:?}", time);
99
}
10-
if meta.set_tag_string("Exif.Image.DateTime", "2008:11:01 21:15:07").is_ok() {
11-
meta.save_to_file("examples/example.jpg").expect("Couldn't save metadata to file");
10+
if meta
11+
.set_tag_string("Exif.Image.DateTime", "2008:11:01 21:15:07")
12+
.is_ok()
13+
{
14+
meta.save_to_file("examples/example.jpg")
15+
.expect("Couldn't save metadata to file");
1216
}
1317
}
1418
}

src/lib.rs

Lines changed: 89 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ impl Metadata {
282282
let ok = gexiv2::gexiv2_metadata_open_path(metadata, c_str_path.as_ptr(), &mut err);
283283
if ok != 1 {
284284
let err_msg = ffi::CStr::from_ptr((*err).message).to_str();
285-
return Err(Rexiv2Error::Internal(err_msg.ok().map(|msg| msg.to_string())));
285+
return Err(Rexiv2Error::Internal(
286+
err_msg.ok().map(|msg| msg.to_string()),
287+
));
286288
}
287289
Ok(Metadata { raw: metadata })
288290
}
@@ -303,13 +305,17 @@ impl Metadata {
303305
let mut err: *mut gexiv2::GError = ptr::null_mut();
304306
unsafe {
305307
let metadata = gexiv2::gexiv2_metadata_new();
306-
let ok = gexiv2::gexiv2_metadata_open_buf(metadata,
307-
data.as_ptr(),
308-
data.len() as libc::c_long,
309-
&mut err);
308+
let ok = gexiv2::gexiv2_metadata_open_buf(
309+
metadata,
310+
data.as_ptr(),
311+
data.len() as libc::c_long,
312+
&mut err,
313+
);
310314
if ok != 1 {
311315
let err_msg = ffi::CStr::from_ptr((*err).message).to_str();
312-
return Err(Rexiv2Error::Internal(err_msg.ok().map(|msg| msg.to_string())));
316+
return Err(Rexiv2Error::Internal(
317+
err_msg.ok().map(|msg| msg.to_string()),
318+
));
313319
}
314320
Ok(Metadata { raw: metadata })
315321
}
@@ -323,7 +329,9 @@ impl Metadata {
323329
let ok = gexiv2::gexiv2_metadata_save_file(self.raw, c_str_path.as_ptr(), &mut err);
324330
if ok != 1 {
325331
let err_msg = ffi::CStr::from_ptr((*err).message).to_str();
326-
return Err(Rexiv2Error::Internal(err_msg.ok().map(|msg| msg.to_string())));
332+
return Err(Rexiv2Error::Internal(
333+
err_msg.ok().map(|msg| msg.to_string()),
334+
));
327335
}
328336
Ok(())
329337
}
@@ -513,9 +521,11 @@ impl Metadata {
513521
let c_str_tag = ffi::CString::new(tag).unwrap();
514522
let c_str_val = ffi::CString::new(value).unwrap();
515523
unsafe {
516-
int_bool_to_result(gexiv2::gexiv2_metadata_set_tag_string(self.raw,
517-
c_str_tag.as_ptr(),
518-
c_str_val.as_ptr()))
524+
int_bool_to_result(gexiv2::gexiv2_metadata_set_tag_string(
525+
self.raw,
526+
c_str_tag.as_ptr(),
527+
c_str_val.as_ptr(),
528+
))
519529
}
520530
}
521531

@@ -525,8 +535,8 @@ impl Metadata {
525535
pub fn get_tag_interpreted_string(&self, tag: &str) -> Result<String> {
526536
let c_str_tag = ffi::CString::new(tag).unwrap();
527537
unsafe {
528-
let c_str_val = gexiv2::gexiv2_metadata_get_tag_interpreted_string(self.raw,
529-
c_str_tag.as_ptr());
538+
let c_str_val =
539+
gexiv2::gexiv2_metadata_get_tag_interpreted_string(self.raw, c_str_tag.as_ptr());
530540
if c_str_val.is_null() {
531541
return Err(Rexiv2Error::NoValue);
532542
}
@@ -573,9 +583,11 @@ impl Metadata {
573583
let mut ptrs: Vec<_> = c_strs.iter().map(|c| c.as_ptr()).collect();
574584
ptrs.push(ptr::null());
575585
unsafe {
576-
int_bool_to_result(gexiv2::gexiv2_metadata_set_tag_multiple(self.raw,
577-
c_str_tag.as_ptr(),
578-
ptrs.as_mut_ptr()))
586+
int_bool_to_result(gexiv2::gexiv2_metadata_set_tag_multiple(
587+
self.raw,
588+
c_str_tag.as_ptr(),
589+
ptrs.as_mut_ptr(),
590+
))
579591
}
580592
}
581593

@@ -593,9 +605,11 @@ impl Metadata {
593605
pub fn set_tag_numeric(&self, tag: &str, value: i32) -> Result<()> {
594606
let c_str_tag = ffi::CString::new(tag).unwrap();
595607
unsafe {
596-
int_bool_to_result(gexiv2::gexiv2_metadata_set_tag_long(self.raw,
597-
c_str_tag.as_ptr(),
598-
value as libc::c_long))
608+
int_bool_to_result(gexiv2::gexiv2_metadata_set_tag_long(
609+
self.raw,
610+
c_str_tag.as_ptr(),
611+
value as libc::c_long,
612+
))
599613
}
600614
}
601615

@@ -620,10 +634,12 @@ impl Metadata {
620634
pub fn set_tag_rational(&self, tag: &str, value: &num_rational::Ratio<i32>) -> Result<()> {
621635
let c_str_tag = ffi::CString::new(tag).unwrap();
622636
unsafe {
623-
int_bool_to_result(gexiv2::gexiv2_metadata_set_exif_tag_rational(self.raw,
624-
c_str_tag.as_ptr(),
625-
*value.numer(),
626-
*value.denom()))
637+
int_bool_to_result(gexiv2::gexiv2_metadata_set_exif_tag_rational(
638+
self.raw,
639+
c_str_tag.as_ptr(),
640+
*value.numer(),
641+
*value.denom(),
642+
))
627643
}
628644
}
629645

@@ -672,15 +688,15 @@ impl Metadata {
672688
/// Returns the f-number used by the camera taking the photograph.
673689
pub fn get_fnumber(&self) -> Option<f64> {
674690
match unsafe { gexiv2::gexiv2_metadata_get_fnumber(self.raw) } {
675-
error_value if error_value < 0.0 => None, // gexiv2 returns -1.0 on error
691+
error_value if error_value < 0.0 => None, // gexiv2 returns -1.0 on error
676692
fnumber => Some(fnumber),
677693
}
678694
}
679695

680696
/// Returns the focal length used by the camera taking the photograph.
681697
pub fn get_focal_length(&self) -> Option<f64> {
682698
match unsafe { gexiv2::gexiv2_metadata_get_focal_length(self.raw) } {
683-
error_value if error_value < 0.0 => None, // gexiv2 returns -1.0 on error
699+
error_value if error_value < 0.0 => None, // gexiv2 returns -1.0 on error
684700
focal => Some(focal),
685701
}
686702
}
@@ -697,8 +713,8 @@ impl Metadata {
697713

698714
/// Get the thumbnail stored in the EXIF data.
699715
pub fn get_thumbnail(&self) -> Option<&[u8]> {
700-
let mut data : *mut u8 = ptr::null_mut();
701-
let mut size : libc::c_int = 0;
716+
let mut data: *mut u8 = ptr::null_mut();
717+
let mut size: libc::c_int = 0;
702718
unsafe {
703719
match gexiv2::gexiv2_metadata_get_exif_thumbnail(self.raw, &mut data, &mut size) {
704720
0 => None,
@@ -709,33 +725,37 @@ impl Metadata {
709725

710726
/// Remove the thumbnail from the EXIF data.
711727
pub fn erase_thumbnail(&self) {
712-
unsafe {
713-
gexiv2::gexiv2_metadata_erase_exif_thumbnail(self.raw)
714-
}
728+
unsafe { gexiv2::gexiv2_metadata_erase_exif_thumbnail(self.raw) }
715729
}
716730

717731
/// Set or replace the EXIF thumbnail with the image in the file.
718732
pub fn set_thumbnail_from_file<S: AsRef<ffi::OsStr>>(&self, path: S) -> Result<()> {
719733
let mut err: *mut gexiv2::GError = ptr::null_mut();
720734
let c_str_path = ffi::CString::new(path.as_ref().as_bytes()).unwrap();
721735
unsafe {
722-
let ok = gexiv2::gexiv2_metadata_set_exif_thumbnail_from_file(self.raw,
723-
c_str_path.as_ptr(),
724-
&mut err);
736+
let ok = gexiv2::gexiv2_metadata_set_exif_thumbnail_from_file(
737+
self.raw,
738+
c_str_path.as_ptr(),
739+
&mut err,
740+
);
725741
if ok != 1 {
726742
let err_msg = ffi::CStr::from_ptr((*err).message).to_str();
727-
return Err(Rexiv2Error::Internal(err_msg.ok().map(|msg| msg.to_string())));
743+
return Err(Rexiv2Error::Internal(
744+
err_msg.ok().map(|msg| msg.to_string()),
745+
));
728746
}
729-
Ok (())
747+
Ok(())
730748
}
731749
}
732750

733751
/// Set or replace the EXIF thumbnail with the content of a buffer.
734752
pub fn set_thumbnail_from_buffer(&self, data: &[u8]) {
735753
unsafe {
736-
gexiv2::gexiv2_metadata_set_exif_thumbnail_from_buffer(self.raw,
737-
data.as_ptr(),
738-
data.len() as libc::c_int)
754+
gexiv2::gexiv2_metadata_set_exif_thumbnail_from_buffer(
755+
self.raw,
756+
data.as_ptr(),
757+
data.len() as libc::c_int,
758+
)
739759
}
740760
}
741761

@@ -746,14 +766,17 @@ impl Metadata {
746766
unsafe {
747767
let ptr = gexiv2::gexiv2_metadata_get_preview_properties(self.raw);
748768
if ptr.is_null() {
749-
return None
769+
return None;
750770
}
751771

752-
let mut previews : Vec<PreviewImage> = vec![];
772+
let mut previews: Vec<PreviewImage> = vec![];
753773
let mut n = 0;
754774
while !(*ptr.offset(n)).is_null() {
755775
let preview_prop = *ptr.offset(n);
756-
previews.push(PreviewImage { raw: preview_prop, metadata: self });
776+
previews.push(PreviewImage {
777+
raw: preview_prop,
778+
metadata: self,
779+
});
757780
n += 1;
758781
}
759782
Some(previews)
@@ -769,17 +792,23 @@ impl Metadata {
769792
let alt = &mut 0.0;
770793
match unsafe { gexiv2::gexiv2_metadata_get_gps_info(self.raw, lon, lat, alt) } {
771794
0 => None,
772-
_ => Some(GpsInfo { longitude: *lon, latitude: *lat, altitude: *alt }),
795+
_ => Some(GpsInfo {
796+
longitude: *lon,
797+
latitude: *lat,
798+
altitude: *alt,
799+
}),
773800
}
774801
}
775802

776803
/// Save the specified GPS values to the metadata.
777804
pub fn set_gps_info(&self, gps: &GpsInfo) -> Result<()> {
778805
unsafe {
779-
int_bool_to_result(gexiv2::gexiv2_metadata_set_gps_info(self.raw,
780-
gps.longitude,
781-
gps.latitude,
782-
gps.altitude))
806+
int_bool_to_result(gexiv2::gexiv2_metadata_set_gps_info(
807+
self.raw,
808+
gps.longitude,
809+
gps.latitude,
810+
gps.altitude,
811+
))
783812
}
784813
}
785814

@@ -796,26 +825,19 @@ impl Drop for Metadata {
796825
}
797826

798827
impl PreviewImage<'_> {
799-
800828
/// Return the size of the preview image in bytes.
801829
pub fn get_size(&self) -> u32 {
802-
unsafe {
803-
gexiv2::gexiv2_preview_properties_get_size(self.raw)
804-
}
830+
unsafe { gexiv2::gexiv2_preview_properties_get_size(self.raw) }
805831
}
806832

807833
/// Return the width of the preview image.
808834
pub fn get_width(&self) -> u32 {
809-
unsafe {
810-
gexiv2::gexiv2_preview_properties_get_width(self.raw)
811-
}
835+
unsafe { gexiv2::gexiv2_preview_properties_get_width(self.raw) }
812836
}
813837

814838
/// Return the height of the preview image.
815839
pub fn get_height(&self) -> u32 {
816-
unsafe {
817-
gexiv2::gexiv2_preview_properties_get_height(self.raw)
818-
}
840+
unsafe { gexiv2::gexiv2_preview_properties_get_height(self.raw) }
819841
}
820842

821843
/// Return the media type of the preview image.
@@ -842,11 +864,10 @@ impl PreviewImage<'_> {
842864

843865
/// Get the preview image data.
844866
pub fn get_data(&self) -> Result<Vec<u8>> {
845-
let image = unsafe {
846-
gexiv2::gexiv2_metadata_get_preview_image(self.metadata.raw, self.raw)
847-
};
867+
let image =
868+
unsafe { gexiv2::gexiv2_metadata_get_preview_image(self.metadata.raw, self.raw) };
848869

849-
let mut size : libc::c_uint = 0;
870+
let mut size: libc::c_uint = 0;
850871
unsafe {
851872
let data = gexiv2::gexiv2_preview_image_get_data(image, &mut size);
852873
let result = if data.is_null() {
@@ -861,9 +882,8 @@ impl PreviewImage<'_> {
861882

862883
/// Save the preview image to a file.
863884
pub fn save_to_file<S: AsRef<ffi::OsStr>>(&self, path: S) -> Result<()> {
864-
let image = unsafe {
865-
gexiv2::gexiv2_metadata_get_preview_image(self.metadata.raw, self.raw)
866-
};
885+
let image =
886+
unsafe { gexiv2::gexiv2_metadata_get_preview_image(self.metadata.raw, self.raw) };
867887

868888
let c_str_path = ffi::CString::new(path.as_ref().as_bytes()).unwrap();
869889
unsafe {
@@ -1037,8 +1057,10 @@ pub fn register_xmp_namespace(name: &str, prefix: &str) -> Result<()> {
10371057
let c_str_name = ffi::CString::new(name).unwrap();
10381058
let c_str_prefix = ffi::CString::new(prefix).unwrap();
10391059
unsafe {
1040-
int_bool_to_result(gexiv2::gexiv2_metadata_register_xmp_namespace(c_str_name.as_ptr(),
1041-
c_str_prefix.as_ptr()))
1060+
int_bool_to_result(gexiv2::gexiv2_metadata_register_xmp_namespace(
1061+
c_str_name.as_ptr(),
1062+
c_str_prefix.as_ptr(),
1063+
))
10421064
}
10431065
}
10441066

@@ -1057,7 +1079,9 @@ pub fn register_xmp_namespace(name: &str, prefix: &str) -> Result<()> {
10571079
pub fn unregister_xmp_namespace(name: &str) -> Result<()> {
10581080
let c_str_name = ffi::CString::new(name).unwrap();
10591081
unsafe {
1060-
int_bool_to_result(gexiv2::gexiv2_metadata_unregister_xmp_namespace(c_str_name.as_ptr()))
1082+
int_bool_to_result(gexiv2::gexiv2_metadata_unregister_xmp_namespace(
1083+
c_str_name.as_ptr(),
1084+
))
10611085
}
10621086
}
10631087

tst/main.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ fn new_from_buffer_error() {
4343
let mut bytes = include_bytes!("sample.png").to_vec();
4444
bytes.swap(0, 1);
4545
let meta_result = rexiv2::Metadata::new_from_buffer(&bytes);
46-
assert_eq!(meta_result,
47-
Err(rexiv2::Rexiv2Error::Internal(Some("unsupported format".to_string()))));
46+
assert_eq!(
47+
meta_result,
48+
Err(rexiv2::Rexiv2Error::Internal(Some(
49+
"unsupported format".to_string()
50+
)))
51+
);
4852
}
4953

5054
#[test]
@@ -76,6 +80,10 @@ fn log_levels() {
7680
#[cfg(feature = "raw-tag-access")]
7781
fn get_tag_raw() {
7882
let meta = rexiv2::Metadata::new_from_buffer(include_bytes!("sample.png")).unwrap();
79-
meta.set_tag_string("Exif.Image.DateTime", "2020:07:12 11:16:35").unwrap();
80-
assert_eq!(meta.get_tag_raw("Exif.Image.DateTime").unwrap(), b"2020:07:12 11:16:35\0");
83+
meta.set_tag_string("Exif.Image.DateTime", "2020:07:12 11:16:35")
84+
.unwrap();
85+
assert_eq!(
86+
meta.get_tag_raw("Exif.Image.DateTime").unwrap(),
87+
b"2020:07:12 11:16:35\0"
88+
);
8189
}

0 commit comments

Comments
 (0)