Skip to content

Commit ae9a89a

Browse files
author
mendelsshop
committed
cargo formatted: most result errors are strings
1 parent 6515454 commit ae9a89a

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

git-function-history-lib/src/languages/umpl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use umpl::{self, parser::Thing};
22

3-
use std::{fmt};
3+
use std::fmt;
44

55
use crate::impl_function_trait;
66

git-function-history-lib/src/lib.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ macro_rules! get_item_from {
2020
($oid:expr, $repo:expr, $typs:ident) => {
2121
git_repository::hash::ObjectId::from($oid)
2222
.attach(&$repo)
23-
.object().map_err(|_| "Could not find object")?
24-
.$typs().map_err(|_| format!("Could not find {} from object", stringify!($typs)))?
23+
.object()
24+
.map_err(|_| "Could not find object")?
25+
.$typs()
26+
.map_err(|_| format!("Could not find {} from object", stringify!($typs)))?
2527
};
2628
}
2729

@@ -414,8 +416,11 @@ fn traverse_tree(
414416
}
415417
},
416418
}
417-
let obh = repo.find_object(i.oid()).map_err(|_| "failed to find object")?;
418-
let objref = objs::ObjectRef::from_bytes(obh.kind, &obh.data).map_err(|_| "failed to get object ref")?;
419+
let obh = repo
420+
.find_object(i.oid())
421+
.map_err(|_| "failed to find object")?;
422+
let objref = objs::ObjectRef::from_bytes(obh.kind, &obh.data)
423+
.map_err(|_| "failed to get object ref")?;
419424
let blob = objref.into_blob();
420425
if let Some(blob) = blob {
421426
files.push((file, String::from_utf8_lossy(blob.data).to_string()));
@@ -534,7 +539,7 @@ fn find_function_in_file_with_commit(
534539
) -> Result<FileType, String> {
535540
let file = match langs {
536541
Language::Rust => {
537-
let functions = rust::find_function_in_file(fc, name)?;
542+
let functions = rust::find_function_in_file(fc, name)?;
538543
FileType::Rust(RustFile::new(file_path.to_string(), functions))
539544
}
540545
// #[cfg(feature = "c_lang")]
@@ -544,25 +549,24 @@ fn find_function_in_file_with_commit(
544549
// }
545550
#[cfg(feature = "unstable")]
546551
Language::Go => {
547-
let functions = languages::go::find_function_in_file(fc, name)?;
552+
let functions = languages::go::find_function_in_file(fc, name)?;
548553
FileType::Go(GoFile::new(file_path.to_string(), functions))
549554
}
550555
Language::Python => {
551-
let functions = languages::python::find_function_in_file(fc, name)?;
556+
let functions = languages::python::find_function_in_file(fc, name)?;
552557
FileType::Python(PythonFile::new(file_path.to_string(), functions))
553558
}
554559
Language::Ruby => {
555-
let functions = languages::ruby::find_function_in_file(fc, name)?;
560+
let functions = languages::ruby::find_function_in_file(fc, name)?;
556561
FileType::Ruby(RubyFile::new(file_path.to_string(), functions))
557562
}
558563
Language::UMPL => {
559-
let functions = languages::umpl::find_function_in_file(fc, name)?;
564+
let functions = languages::umpl::find_function_in_file(fc, name)?;
560565
FileType::UMPL(UMPLFile::new(file_path.to_string(), functions))
561566
}
562567
Language::All => match file_path.split('.').last() {
563568
Some("rs") => {
564-
565-
let functions = rust::find_function_in_file(fc, name)?;
569+
let functions = rust::find_function_in_file(fc, name)?;
566570
FileType::Rust(RustFile::new(file_path.to_string(), functions))
567571
}
568572
// #[cfg(feature = "c_lang")]
@@ -571,16 +575,16 @@ fn find_function_in_file_with_commit(
571575
// FileType::C(CFile::new(file_path.to_string(), functions))
572576
// }
573577
Some("py" | "pyw") => {
574-
let functions = languages::python::find_function_in_file(fc, name)?;
578+
let functions = languages::python::find_function_in_file(fc, name)?;
575579
FileType::Python(PythonFile::new(file_path.to_string(), functions))
576580
}
577581
#[cfg(feature = "unstable")]
578582
Some("go") => {
579-
let functions = languages::go::find_function_in_file(fc, name)?;
583+
let functions = languages::go::find_function_in_file(fc, name)?;
580584
FileType::Go(GoFile::new(file_path.to_string(), functions))
581585
}
582586
Some("rb") => {
583-
let functions = languages::ruby::find_function_in_file(fc, name)?;
587+
let functions = languages::ruby::find_function_in_file(fc, name)?;
584588
FileType::Ruby(RubyFile::new(file_path.to_string(), functions))
585589
}
586590
_ => Err("unknown file type")?,
@@ -618,7 +622,6 @@ trait UnwrapToError<T> {
618622
}
619623

620624
impl<T> UnwrapToError<T> for Option<T> {
621-
622625
fn unwrap_to_error(self, message: &str) -> Result<T, String> {
623626
self.map_or_else(|| Err(message.to_string()), |val| Ok(val))
624627
}

git-function-history-lib/src/types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ impl FileTrait for FileType {
5858
fn filter_by(&self, filter: &Filter) -> Result<Self, String> {
5959
match self {
6060
Self::Rust(file) => {
61-
let filtered = file.filter_by(filter)?;
61+
let filtered = file.filter_by(filter)?;
6262
Ok(Self::Rust(filtered))
6363
}
6464
Self::Python(file) => {
65-
let filtered = file.filter_by(filter)?;
65+
let filtered = file.filter_by(filter)?;
6666
Ok(Self::Python(filtered))
6767
}
6868

@@ -73,15 +73,15 @@ impl FileTrait for FileType {
7373
// }
7474
#[cfg(feature = "unstable")]
7575
Self::Go(file) => {
76-
let filtered = file.filter_by(filter)?;
76+
let filtered = file.filter_by(filter)?;
7777
Ok(Self::Go(filtered))
7878
}
7979
Self::Ruby(file) => {
80-
let filtered = file.filter_by(filter)?;
80+
let filtered = file.filter_by(filter)?;
8181
Ok(Self::Ruby(filtered))
8282
}
8383
Self::UMPL(file) => {
84-
let filtered = file.filter_by(filter)?;
84+
let filtered = file.filter_by(filter)?;
8585
Ok(Self::UMPL(filtered))
8686
}
8787
}
@@ -158,7 +158,7 @@ impl Commit {
158158
Ok(Self {
159159
commit_hash: commit_hash.to_string(),
160160
files,
161-
date:DateTime::parse_from_rfc2822(date).map_err(|e| e.to_string())?,
161+
date: DateTime::parse_from_rfc2822(date).map_err(|e| e.to_string())?,
162162
current_pos: 0,
163163
current_iter_pos: 0,
164164
author: author.to_string(),

0 commit comments

Comments
 (0)