Skip to content

Commit 14c1318

Browse files
author
Jordan Maples
committed
fmt
1 parent f2fc0e6 commit 14c1318

2 files changed

Lines changed: 38 additions & 35 deletions

File tree

diskann-benchmark-runner/src/input.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ pub(crate) mod internal {
199199
Ok(serde_json::to_value(T::example())?)
200200
}
201201
fn schema(&self) -> serde_json::Value {
202-
let generator =
203-
schemars::generate::SchemaSettings::default().into_generator();
202+
let generator = schemars::generate::SchemaSettings::default().into_generator();
204203
let schema = generator.into_root_schema_for::<T::Raw>();
205204
serde_json::to_value(schema).unwrap_or_default()
206205
}

diskann-benchmark-runner/src/schema.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ use serde_json::Value;
2020
/// The schema should be the root schema object produced by `schemars::generate::schema_for`.
2121
/// It may contain `$defs` for referenced type definitions.
2222
pub fn render(schema: &Value, output: &mut dyn Write) -> io::Result<()> {
23-
let defs = schema
24-
.get("$defs")
25-
.or_else(|| schema.get("definitions"));
23+
let defs = schema.get("$defs").or_else(|| schema.get("definitions"));
2624

2725
let mut buf = String::new();
2826
render_node(schema, defs, &mut buf, 0, true);
@@ -35,9 +33,7 @@ pub fn render(schema: &Value, output: &mut dyn Write) -> io::Result<()> {
3533
/// At each path segment, this descends into `properties.<segment>`, resolving any `$ref`
3634
/// along the way.
3735
pub fn resolve_path(schema: &Value, path: &str) -> Option<Value> {
38-
let defs = schema
39-
.get("$defs")
40-
.or_else(|| schema.get("definitions"));
36+
let defs = schema.get("$defs").or_else(|| schema.get("definitions"));
4137

4238
let mut current = resolve(schema, defs);
4339

@@ -59,7 +55,9 @@ pub fn resolve_path(schema: &Value, path: &str) -> Option<Value> {
5955
for variant in variants {
6056
// For $ref + inline properties pattern, check the resolved ref.
6157
let resolved_variant = resolve(variant, defs);
62-
if let Some(prop) = resolved_variant.get("properties").and_then(|p| p.get(segment))
58+
if let Some(prop) = resolved_variant
59+
.get("properties")
60+
.and_then(|p| p.get(segment))
6361
{
6462
current = resolve(prop, defs);
6563
found = true;
@@ -88,13 +86,7 @@ pub fn resolve_path(schema: &Value, path: &str) -> Option<Value> {
8886
const MAX_DEPTH: usize = 16;
8987

9088
/// Render a single schema node into the buffer at the given indentation depth.
91-
fn render_node(
92-
node: &Value,
93-
defs: Option<&Value>,
94-
buf: &mut String,
95-
depth: usize,
96-
_is_last: bool,
97-
) {
89+
fn render_node(node: &Value, defs: Option<&Value>, buf: &mut String, depth: usize, _is_last: bool) {
9890
if depth >= MAX_DEPTH {
9991
write_indented(buf, depth, &format!("{}", "...".dimmed()));
10092
return;
@@ -283,18 +275,14 @@ fn render_variants(variants: &[Value], defs: Option<&Value>, buf: &mut String, d
283275
// properties containing the tag.
284276
if variant.get("$ref").is_some() {
285277
if let Some(inline_props) = variant.get("properties").and_then(Value::as_object) {
286-
let tag = inline_props
287-
.values()
288-
.find_map(extract_tag_value);
278+
let tag = inline_props.values().find_map(extract_tag_value);
289279

290280
if let Some(tag) = tag {
291281
let resolved = resolve(variant, defs);
292282
let desc = resolved.get("description").and_then(Value::as_str);
293283
write_variant_header(buf, depth, connector, &tag, desc);
294284

295-
if let Some(ref_props) =
296-
resolved.get("properties").and_then(Value::as_object)
297-
{
285+
if let Some(ref_props) = resolved.get("properties").and_then(Value::as_object) {
298286
let entries: Vec<_> = ref_props.iter().collect();
299287
render_field_list(&entries, resolved, defs, buf, depth, child_prefix);
300288
}
@@ -328,9 +316,7 @@ fn render_variants(variants: &[Value], defs: Option<&Value>, buf: &mut String, d
328316
let desc = inner.get("description").and_then(Value::as_str);
329317
write_variant_header(buf, depth, connector, variant_name, desc);
330318

331-
if let Some(inner_props) =
332-
inner.get("properties").and_then(Value::as_object)
333-
{
319+
if let Some(inner_props) = inner.get("properties").and_then(Value::as_object) {
334320
let entries: Vec<_> = inner_props.iter().collect();
335321
render_field_list(&entries, inner, defs, buf, depth, child_prefix);
336322
}
@@ -363,7 +349,11 @@ fn render_field_list(
363349

364350
for (i, (name, schema)) in entries.iter().enumerate() {
365351
let is_last_field = i == entries.len() - 1;
366-
let field_connector = if is_last_field { "└── " } else { "├── " };
352+
let field_connector = if is_last_field {
353+
"└── "
354+
} else {
355+
"├── "
356+
};
367357
let optional_str = if !required.contains(&name.as_str()) {
368358
format!(" {}", "(optional)".dimmed())
369359
} else {
@@ -397,7 +387,11 @@ fn render_array(
397387
) {
398388
let resolved = resolve(items, defs);
399389
let item_summary = type_summary(resolved);
400-
write_indented(buf, depth, &format!("{}", format!("array of {item_summary}").cyan()));
390+
write_indented(
391+
buf,
392+
depth,
393+
&format!("{}", format!("array of {item_summary}").cyan()),
394+
);
401395
}
402396

403397
// ─────────────────────────────────────────────────────────────────────────────
@@ -586,10 +580,21 @@ fn write_description(buf: &mut String, depth: usize, cont_prefix: &str, desc: &s
586580
for (i, line) in lines_to_print.iter().enumerate() {
587581
let trimmed = line.trim();
588582
if i == 0 {
589-
let _ = writeln!(buf, "{indent}{}{}", cont_prefix.dimmed(), format!("# {trimmed}").green());
583+
let _ = writeln!(
584+
buf,
585+
"{indent}{}{}",
586+
cont_prefix.dimmed(),
587+
format!("# {trimmed}").green()
588+
);
590589
} else {
591590
// Continuation lines: align with the text after "# "
592-
let _ = writeln!(buf, "{indent}{}{} {}", cont_prefix.dimmed(), "#".green(), trimmed.green());
591+
let _ = writeln!(
592+
buf,
593+
"{indent}{}{} {}",
594+
cont_prefix.dimmed(),
595+
"#".green(),
596+
trimmed.green()
597+
);
593598
}
594599
}
595600
}
@@ -643,7 +648,10 @@ mod tests {
643648

644649
let text = render_to_string::<Config>();
645650
// required_field should NOT be marked optional
646-
assert!(!text.contains("required_field: string (optional)"), "got: {text}");
651+
assert!(
652+
!text.contains("required_field: string (optional)"),
653+
"got: {text}"
654+
);
647655
assert!(text.contains("(optional)"), "got: {text}");
648656
}
649657

@@ -679,11 +687,7 @@ mod tests {
679687
/// Use the medoid.
680688
Medoid,
681689
/// Use random vectors with given parameters.
682-
RandomVectors {
683-
norm: f32,
684-
nsamples: u32,
685-
seed: u64,
686-
},
690+
RandomVectors { norm: f32, nsamples: u32, seed: u64 },
687691
}
688692

689693
#[derive(JsonSchema)]

0 commit comments

Comments
 (0)