Skip to content

Commit

Permalink
style: use &str instead of &String since it's more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehri01 committed Jan 7, 2025
1 parent 4419b13 commit e68e7db
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/field_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum DoInsert {

pub fn get_field<'a>(
path: &[String],
last_field: &String,
last_field: &str,
do_insert: DoInsert,
doc: &'a mut DocumentMut,
) -> Result<TomlValue<'a>> {
Expand All @@ -32,7 +32,7 @@ fn descend_table<'a>(
table: &'a mut Table,
path: &[String],
do_insert: DoInsert,
last_field: &String,
last_field: &str,
) -> Result<TomlValue<'a>> {
let segment = match path.first() {
Some(segment) => segment,
Expand Down Expand Up @@ -67,7 +67,7 @@ fn descend_item<'a>(
item: &'a mut Item,
path: &[String],
do_insert: DoInsert,
last_field: &String,
last_field: &str,
) -> Result<TomlValue<'a>> {
match item {
Item::Table(table) => descend_table(table, path, do_insert, last_field),
Expand All @@ -81,7 +81,7 @@ fn descend_value<'a>(
value: &'a mut Value,
path: &[String],
do_insert: DoInsert,
last_field: &String,
last_field: &str,
) -> Result<TomlValue<'a>> {
match value {
Value::Array(array) => descend_array(array, path, do_insert, last_field),
Expand All @@ -101,7 +101,7 @@ fn descend_array_of_tables<'a>(
array: &'a mut ArrayOfTables,
path: &[String],
do_insert: DoInsert,
last_field: &String,
last_field: &str,
) -> Result<TomlValue<'a>> {
let segment = match path.first() {
Some(segment) => segment,
Expand Down Expand Up @@ -141,7 +141,7 @@ fn descend_inline_table<'a>(
inline_table: &'a mut InlineTable,
path: &[String],
do_insert: DoInsert,
last_field: &String,
last_field: &str,
) -> Result<TomlValue<'a>> {
let segment = match path.first() {
Some(segment) => segment,
Expand All @@ -163,7 +163,7 @@ fn descend_array<'a>(
array: &'a mut Array,
path: &[String],
do_insert: DoInsert,
last_field: &String,
last_field: &str,
) -> Result<TomlValue<'a>> {
let segment = match path.first() {
Some(segment) => segment,
Expand Down Expand Up @@ -206,7 +206,7 @@ bla = "bla"
let mut doc = doc_string.parse::<DocumentMut>().unwrap();
let val = get_field(
&["foo".to_string()],
&"bar".to_string(),
"bar",
DoInsert::Yes,
&mut doc,
)
Expand All @@ -224,7 +224,7 @@ bla = "bla"
let doc_string = r#"test = [ 1 ]"#;
let mut doc = doc_string.parse::<DocumentMut>().unwrap();
let fields = ["test".to_string()];
let val = get_field(&(fields), &"1".to_string(), DoInsert::Yes, &mut doc).unwrap();
let val = get_field(&(fields), "1", DoInsert::Yes, &mut doc).unwrap();

if let TomlValue::Array(array) = val {
assert_eq!(array.len(), 1);
Expand All @@ -243,7 +243,7 @@ foo = "baz"
"#;
let mut doc = doc_string.parse::<DocumentMut>().unwrap();
let fields = ["test".to_string()];
let val = get_field(&(fields), &"2".to_string(), DoInsert::Yes, &mut doc).unwrap();
let val = get_field(&(fields), "2", DoInsert::Yes, &mut doc).unwrap();

if let TomlValue::ArrayOfTables(array) = val {
assert_eq!(array.len(), 2);
Expand Down

0 comments on commit e68e7db

Please sign in to comment.