Skip to content

Commit

Permalink
#2: refactor AsRef<str>
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Mikhailov committed Mar 1, 2023
1 parent 32b7788 commit eddcf65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 5 additions & 5 deletions config-manager-proc/src/utils/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ use strum::IntoEnumIterator;
use super::attributes::*;
use crate::*;

fn str_to_config_format_repr<T: AsRef<str>>(s: T) -> String {
match s.as_ref() {
fn str_to_config_format_repr(s: &str) -> String {
match s {
"json" | "json5" | "toml" | "yaml" | "ron" => {
let capitalize_first = |s: &str| -> String {
let mut chars = s.chars();
let first_char = chars.next().unwrap();
first_char.to_uppercase().to_string() + &chars.collect::<String>()
};

let accepted_format = capitalize_first(s.as_ref());
let accepted_format = capitalize_first(s);
let pref = "::config_manager::__private::config::FileFormat::".to_string();
pref + &accepted_format
}
_ => panic!("{} format is not supported", s.as_ref()),
_ => panic!("{} format is not supported", s),
}
}

Expand Down Expand Up @@ -117,7 +117,7 @@ fn handle_file_attribute(
.skip(1)
.take(format_atr.len() - 2)
.collect();
file_format = Some(str_to_config_format_repr(drop_fst_and_lst))
file_format = Some(str_to_config_format_repr(&drop_fst_and_lst))
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions config-manager-proc/src/utils/parser/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ pub(crate) fn path_to_string(path: &Path) -> String {
.to_string()
}

pub(crate) fn compare_attribute_name<S: AsRef<str> + PartialEq<String>>(
a: &Attribute,
name: S,
) -> bool {
pub(crate) fn compare_attribute_name(a: &Attribute, name: &str) -> bool {
name == path_to_string(&a.path)
}

Expand Down

0 comments on commit eddcf65

Please sign in to comment.