lib: run rustfmt

This commit is contained in:
Luca BRUNO 2021-12-01 15:18:47 +00:00 committed by Colin Walters
parent 810e86d4fb
commit 83b03d2996
3 changed files with 33 additions and 17 deletions

View File

@ -1,6 +1,6 @@
use std::fmt::Display; use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Error; use std::fmt::Error;
use std::fmt::Formatter;
/// Details of an object in an OSTree repo. It contains information about if /// Details of an object in an OSTree repo. It contains information about if
/// the object is "loose", and contains a list of pack file checksums in which /// the object is "loose", and contains a list of pack file checksums in which
@ -32,11 +32,13 @@ impl ObjectDetails {
} }
} }
impl Display for ObjectDetails{ impl Display for ObjectDetails {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
write!(f, "Object is {} and appears in {} checksums", write!(
if self.loose {"loose"} else {"not loose"}, f,
self.object_appearances.len() ) "Object is {} and appears in {} checksums",
if self.loose { "loose" } else { "not loose" },
self.object_appearances.len()
)
} }
} }

View File

@ -1,6 +1,6 @@
#[cfg(any(feature = "v2016_4", feature = "dox"))] #[cfg(any(feature = "v2016_4", feature = "dox"))]
use crate::RepoListRefsExtFlags; use crate::RepoListRefsExtFlags;
use crate::{Checksum, ObjectName, ObjectDetails, ObjectType, Repo, RepoTransactionStats}; use crate::{Checksum, ObjectDetails, ObjectName, ObjectType, Repo, RepoTransactionStats};
use ffi::OstreeRepoListObjectsFlags; use ffi::OstreeRepoListObjectsFlags;
use glib::ffi as glib_sys; use glib::ffi as glib_sys;
use glib::{self, translate::*, Error, IsA}; use glib::{self, translate::*, Error, IsA};
@ -30,7 +30,8 @@ unsafe extern "C" fn read_variant_object_map(
) { ) {
let key: glib::Variant = from_glib_none(key as *const glib_sys::GVariant); let key: glib::Variant = from_glib_none(key as *const glib_sys::GVariant);
let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant); let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant);
let set: &mut HashMap<ObjectName, ObjectDetails> = &mut *(hash_set as *mut HashMap<ObjectName, ObjectDetails>); let set: &mut HashMap<ObjectName, ObjectDetails> =
&mut *(hash_set as *mut HashMap<ObjectName, ObjectDetails>);
if let Some(details) = ObjectDetails::new_from_variant(value) { if let Some(details) = ObjectDetails::new_from_variant(value) {
set.insert(ObjectName::new_from_variant(key), details); set.insert(ObjectName::new_from_variant(key), details);
} }
@ -47,7 +48,9 @@ unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable) -> Has
set set
} }
unsafe fn from_glib_container_variant_map(ptr: *mut glib_sys::GHashTable) -> HashMap<ObjectName, ObjectDetails> { unsafe fn from_glib_container_variant_map(
ptr: *mut glib_sys::GHashTable,
) -> HashMap<ObjectName, ObjectDetails> {
let mut set = HashMap::new(); let mut set = HashMap::new();
glib_sys::g_hash_table_foreach( glib_sys::g_hash_table_foreach(
ptr, ptr,
@ -186,7 +189,7 @@ impl Repo {
flags, flags,
&mut hashtable, &mut hashtable,
cancellable.map(AsRef::as_ref).to_glib_none().0, cancellable.map(AsRef::as_ref).to_glib_none().0,
&mut error &mut error,
); );
if error.is_null() { if error.is_null() {

View File

@ -11,17 +11,28 @@ fn list_repo_objects() {
let mut file_cnt = 0; let mut file_cnt = 0;
let mut commit_cnt = 0; let mut commit_cnt = 0;
let objects = repo.repo.list_objects( ffi::OSTREE_REPO_LIST_OBJECTS_ALL, NONE_CANCELLABLE).expect("List Objects"); let objects = repo
.repo
.list_objects(ffi::OSTREE_REPO_LIST_OBJECTS_ALL, NONE_CANCELLABLE)
.expect("List Objects");
for (object, _items) in objects { for (object, _items) in objects {
match object.object_type() { match object.object_type() {
ObjectType::DirTree => { dirtree_cnt += 1; }, ObjectType::DirTree => {
ObjectType::DirMeta => { dirmeta_cnt += 1; }, dirtree_cnt += 1;
ObjectType::File => { file_cnt += 1; }, }
ObjectType::DirMeta => {
dirmeta_cnt += 1;
}
ObjectType::File => {
file_cnt += 1;
}
ObjectType::Commit => { ObjectType::Commit => {
assert_eq!(commit_checksum.to_string(), object.checksum()); assert_eq!(commit_checksum.to_string(), object.checksum());
commit_cnt += 1; commit_cnt += 1;
}, }
x => { panic!("unexpected object type {}", x ); } x => {
panic!("unexpected object type {}", x);
}
} }
} }
assert_eq!(dirtree_cnt, 2); assert_eq!(dirtree_cnt, 2);