Skip to content

Commit 0c634ad

Browse files
authored
style: simplify strings with string interpolation (quickwit-oss#2412)
* style: simplify strings with string interpolation * fix: formatting
1 parent 2e3641c commit 0c634ad

File tree

20 files changed

+44
-55
lines changed

20 files changed

+44
-55
lines changed

benches/agg_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ fn get_test_index_bench(cardinality: Cardinality) -> tantivy::Result<Index> {
349349
let lg_norm = rand_distr::LogNormal::new(2.996f64, 0.979f64).unwrap();
350350

351351
let many_terms_data = (0..150_000)
352-
.map(|num| format!("author{}", num))
352+
.map(|num| format!("author{num}"))
353353
.collect::<Vec<_>>();
354354
{
355355
let mut rng = StdRng::from_seed([1u8; 32]);

benches/index-bench.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ pub fn hdfs_index_benchmark(c: &mut Criterion) {
141141
let parse_json = false;
142142
// for parse_json in [false, true] {
143143
let suffix = if parse_json {
144-
format!("{}-with-json-parsing", suffix)
144+
format!("{suffix}-with-json-parsing")
145145
} else {
146146
suffix.to_string()
147147
};
148148

149-
let bench_name = format!("{}{}", prefix, suffix);
149+
let bench_name = format!("{prefix}{suffix}");
150150
group.bench_function(bench_name, |b| {
151151
benchmark(b, HDFS_LOGS, schema.clone(), commit, parse_json, is_dynamic)
152152
});

examples/index_from_multiple_threads.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() -> tantivy::Result<()> {
6161
debris of the winter’s flooding; and sycamores with mottled, white, recumbent \
6262
limbs and branches that arch over the pool"
6363
))?;
64-
println!("add doc {} from thread 1 - opstamp {}", i, opstamp);
64+
println!("add doc {i} from thread 1 - opstamp {opstamp}");
6565
thread::sleep(Duration::from_millis(20));
6666
}
6767
Result::<(), TantivyError>::Ok(())
@@ -82,7 +82,7 @@ fn main() -> tantivy::Result<()> {
8282
body => "Some great book description..."
8383
))?
8484
};
85-
println!("add doc {} from thread 2 - opstamp {}", i, opstamp);
85+
println!("add doc {i} from thread 2 - opstamp {opstamp}");
8686
thread::sleep(Duration::from_millis(10));
8787
}
8888
Result::<(), TantivyError>::Ok(())

src/aggregation/agg_req_with_accessor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ fn get_missing_val(
335335
}
336336
_ => {
337337
return Err(crate::TantivyError::InvalidArgument(format!(
338-
"Missing value {:?} for field {} is not supported for column type {:?}",
339-
missing, field_name, column_type
338+
"Missing value {missing:?} for field {field_name} is not supported for column \
339+
type {column_type:?}"
340340
)));
341341
}
342342
};
@@ -403,7 +403,7 @@ fn get_dynamic_columns(
403403
.iter()
404404
.map(|h| h.open())
405405
.collect::<io::Result<_>>()?;
406-
assert!(!ff_fields.is_empty(), "field {} not found", field_name);
406+
assert!(!ff_fields.is_empty(), "field {field_name} not found");
407407
Ok(cols)
408408
}
409409

src/aggregation/bucket/term_agg.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,7 @@ impl SegmentTermCollector {
357357
) -> crate::Result<Self> {
358358
if field_type == ColumnType::Bytes {
359359
return Err(TantivyError::InvalidArgument(format!(
360-
"terms aggregation is not supported for column type {:?}",
361-
field_type
360+
"terms aggregation is not supported for column type {field_type:?}"
362361
)));
363362
}
364363
let term_buckets = TermBuckets::default();

src/aggregation/metric/top_hits.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ impl<'de> Deserialize<'de> for KeyOrder {
131131
))?;
132132
if key_order.next().is_some() {
133133
return Err(serde::de::Error::custom(format!(
134-
"Expected exactly one key-value pair in sort parameter of top_hits, found {:?}",
135-
key_order
134+
"Expected exactly one key-value pair in sort parameter of top_hits, found \
135+
{key_order:?}"
136136
)));
137137
}
138138
Ok(Self { field, order })
@@ -144,27 +144,22 @@ fn globbed_string_to_regex(glob: &str) -> Result<Regex, crate::TantivyError> {
144144
// Replace `*` glob with `.*` regex
145145
let sanitized = format!("^{}$", regex::escape(glob).replace(r"\*", ".*"));
146146
Regex::new(&sanitized.replace('*', ".*")).map_err(|e| {
147-
crate::TantivyError::SchemaError(format!(
148-
"Invalid regex '{}' in docvalue_fields: {}",
149-
glob, e
150-
))
147+
crate::TantivyError::SchemaError(format!("Invalid regex '{glob}' in docvalue_fields: {e}"))
151148
})
152149
}
153150

154151
fn use_doc_value_fields_err(parameter: &str) -> crate::Result<()> {
155152
Err(crate::TantivyError::AggregationError(
156153
AggregationError::InvalidRequest(format!(
157-
"The `{}` parameter is not supported, only `docvalue_fields` is supported in \
158-
`top_hits` aggregation",
159-
parameter
154+
"The `{parameter}` parameter is not supported, only `docvalue_fields` is supported in \
155+
`top_hits` aggregation"
160156
)),
161157
))
162158
}
163159
fn unsupported_err(parameter: &str) -> crate::Result<()> {
164160
Err(crate::TantivyError::AggregationError(
165161
AggregationError::InvalidRequest(format!(
166-
"The `{}` parameter is not supported in the `top_hits` aggregation",
167-
parameter
162+
"The `{parameter}` parameter is not supported in the `top_hits` aggregation"
168163
)),
169164
))
170165
}
@@ -217,8 +212,7 @@ impl TopHitsAggregation {
217212
.collect::<Vec<_>>();
218213
assert!(
219214
!fields.is_empty(),
220-
"No fields matched the glob '{}' in docvalue_fields",
221-
field
215+
"No fields matched the glob '{field}' in docvalue_fields"
222216
);
223217
Ok(fields)
224218
})
@@ -254,7 +248,7 @@ impl TopHitsAggregation {
254248
.map(|field| {
255249
let accessors = accessors
256250
.get(field)
257-
.unwrap_or_else(|| panic!("field '{}' not found in accessors", field));
251+
.unwrap_or_else(|| panic!("field '{field}' not found in accessors"));
258252

259253
let values: Vec<FastFieldValue> = accessors
260254
.iter()

src/aggregation/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,14 @@ use serde::de::{self, Visitor};
158158
use serde::{Deserialize, Deserializer, Serialize};
159159

160160
fn parse_str_into_f64<E: de::Error>(value: &str) -> Result<f64, E> {
161-
let parsed = value.parse::<f64>().map_err(|_err| {
162-
de::Error::custom(format!("Failed to parse f64 from string: {:?}", value))
163-
})?;
161+
let parsed = value
162+
.parse::<f64>()
163+
.map_err(|_err| de::Error::custom(format!("Failed to parse f64 from string: {value:?}")))?;
164164

165165
// Check if the parsed value is NaN or infinity
166166
if parsed.is_nan() || parsed.is_infinite() {
167167
Err(de::Error::custom(format!(
168-
"Value is not a valid f64 (NaN or Infinity): {:?}",
169-
value
168+
"Value is not a valid f64 (NaN or Infinity): {value:?}"
170169
)))
171170
} else {
172171
Ok(parsed)

src/collector/facet_collector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ mod tests {
598598
let mid = n % 4;
599599
n /= 4;
600600
let leaf = n % 5;
601-
Facet::from(&format!("/top{}/mid{}/leaf{}", top, mid, leaf))
601+
Facet::from(&format!("/top{top}/mid{mid}/leaf{leaf}"))
602602
})
603603
.collect();
604604
for i in 0..num_facets * 10 {
@@ -737,7 +737,7 @@ mod tests {
737737
vec![("a", 10), ("b", 100), ("c", 7), ("d", 12), ("e", 21)]
738738
.into_iter()
739739
.flat_map(|(c, count)| {
740-
let facet = Facet::from(&format!("/facet/{}", c));
740+
let facet = Facet::from(&format!("/facet/{c}"));
741741
let doc = doc!(facet_field => facet);
742742
iter::repeat(doc).take(count)
743743
})
@@ -785,7 +785,7 @@ mod tests {
785785
let docs: Vec<TantivyDocument> = vec![("b", 2), ("a", 2), ("c", 4)]
786786
.into_iter()
787787
.flat_map(|(c, count)| {
788-
let facet = Facet::from(&format!("/facet/{}", c));
788+
let facet = Facet::from(&format!("/facet/{c}"));
789789
let doc = doc!(facet_field => facet);
790790
iter::repeat(doc).take(count)
791791
})

src/core/json_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,14 @@ mod tests {
338338
let mut term = Term::from_field_json_path(field, "attributes.color", false);
339339
term.append_type_and_str("red");
340340
assert_eq!(
341-
format!("{:?}", term),
341+
format!("{term:?}"),
342342
"Term(field=1, type=Json, path=attributes.color, type=Str, \"red\")"
343343
);
344344

345345
let mut term = Term::from_field_json_path(field, "attributes.dimensions.width", false);
346346
term.append_type_and_fast_value(400i64);
347347
assert_eq!(
348-
format!("{:?}", term),
348+
format!("{term:?}"),
349349
"Term(field=1, type=Json, path=attributes.dimensions.width, type=I64, 400)"
350350
);
351351
}

src/directory/mmap_directory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ mod tests {
566566
let mmap_directory = MmapDirectory::create_from_tempdir().unwrap();
567567
let num_paths = 10;
568568
let paths: Vec<PathBuf> = (0..num_paths)
569-
.map(|i| PathBuf::from(&*format!("file_{}", i)))
569+
.map(|i| PathBuf::from(&*format!("file_{i}")))
570570
.collect();
571571
{
572572
for path in &paths {

0 commit comments

Comments
 (0)