diskann_benchmark_runner/lib.rs
1/*
2 * Copyright (c) Microsoft Corporation.
3 * Licensed under the MIT license.
4 */
5
6//! A moderately functional utility for making simple benchmarking CLI applications.
7
8mod checker;
9mod jobs;
10mod result;
11
12pub mod any;
13pub mod app;
14pub mod dispatcher;
15pub mod files;
16pub mod output;
17pub mod registry;
18pub mod utils;
19
20pub use any::Any;
21pub use app::App;
22pub use checker::{CheckDeserialization, Checker};
23pub use output::Output;
24pub use result::Checkpoint;
25
26#[cfg(any(test, feature = "test-app"))]
27pub mod test;
28
29#[cfg(any(test, feature = "ux-tools"))]
30#[doc(hidden)]
31pub mod ux;
32
33//-------//
34// Input //
35//-------//
36
37pub trait Input {
38 /// Return the discriminant associated with this type.
39 ///
40 /// This is used to map inputs types to their respective parsers.
41 ///
42 /// Well formed implementations should always return the same result.
43 fn tag(&self) -> &'static str;
44
45 /// Attempt to deserialize an opaque object from the raw `serialized` representation.
46 ///
47 /// Deserialized values can be constructed and returned via [`Checker::any`],
48 /// [`Any::new`] or [`Any::raw`].
49 ///
50 /// If using the [`Any`] constructors directly, implementations should associate
51 /// [`Self::tag`] with the returned `Any`. If [`Checker::any`] is used - this will
52 /// happen automatically.
53 ///
54 /// Implementations are **strongly** encouraged to implement [`CheckDeserialization`]
55 /// and use this API to ensure shared resources (like input files or output files)
56 /// are correctly resolved and properly shared among all jobs in a benchmark run.
57 fn try_deserialize(
58 &self,
59 serialized: &serde_json::Value,
60 checker: &mut Checker,
61 ) -> anyhow::Result<Any>;
62
63 /// Print an example JSON representation of objects this input is expected to parse.
64 ///
65 /// Well formed implementations should passing the returned [`serde_json::Value`] back
66 /// to [`Self::try_deserialize`] correctly deserializes, though it need not necessarily
67 /// pass [`CheckDeserialization`].
68 fn example(&self) -> anyhow::Result<serde_json::Value>;
69}