pub struct SourcePack {
pub root: PathBuf,
pub manifest: PackManifest,
pub rules: Vec<Rule>,
pub source_digest: [u8; 32],
}Fields§
§root: PathBuf§manifest: PackManifest§rules: Vec<Rule>§source_digest: [u8; 32]Implementations§
Source§impl SourcePack
impl SourcePack
Sourcepub fn load(root: &Path) -> Result<Self, String>
pub fn load(root: &Path) -> Result<Self, String>
Load and validate one explicit source-pack directory.
§Errors
Returns an error for unsafe paths, invalid JSON, schema errors, conflicts, or size limits.
Examples found in repository?
examples/rule_benchmark.rs (line 92)
66fn benchmark_external() -> Result<(Duration, Duration, usize), String> {
67 let directory = TempDir::new().map_err(|error| error.to_string())?;
68 let source_root = directory.path().join("source");
69 let rules_root = source_root.join("rules");
70 fs::create_dir_all(&rules_root).map_err(|error| error.to_string())?;
71 let mut paths = Vec::with_capacity(EXTERNAL_RULES);
72 for index in 0..EXTERNAL_RULES {
73 let relative = format!("rules/rule-{index:04}.json");
74 let id = format!("bench/rule-{index:04}");
75 let program = format!("bench{index:04}");
76 let body = format!(
77 "{{\"id\":{id:?},\"match\":{{\"program\":[{program:?}]}},\"action\":\"reduce\",\"reducer\":{{\"kind\":\"list_summary\"}},\"success\":{{\"max_line_bytes\":16384,\"max_output_bytes\":32768,\"min_savings_bytes\":120,\"min_savings_basis_points\":1000}},\"failure\":{{\"max_line_bytes\":16384,\"max_output_bytes\":65536,\"min_savings_bytes\":120,\"min_savings_basis_points\":500}}}}"
78 );
79 fs::write(source_root.join(&relative), body).map_err(|error| error.to_string())?;
80 paths.push(relative);
81 }
82 let manifest = serde_json::json!({
83 "schema_version": 1,
84 "id": "benchmark-pack",
85 "rules": paths,
86 });
87 fs::write(
88 source_root.join("pack.json"),
89 serde_json::to_vec(&manifest).map_err(|error| error.to_string())?,
90 )
91 .map_err(|error| error.to_string())?;
92 let source = SourcePack::load(&source_root)?;
93 let body = compile(&source)?;
94 let pack_path = directory.path().join("benchmark.yrp");
95 fs::write(&pack_path, &body).map_err(|error| error.to_string())?;
96 let arguments = vec!["bench0999".to_owned()];
97 let request = PackRequest {
98 path: pack_path,
99 expected_digest: Some(source.source_digest),
100 expected_compiled_digest: None,
101 };
102 let cold_started = Instant::now();
103 let mut cold_registry = Registry::load(std::slice::from_ref(&request))?;
104 if !matches!(
105 cold_registry.select(black_box(&arguments))?,
106 Selection::Reduce(_)
107 ) {
108 return Err("external benchmark command was not selected".to_owned());
109 }
110 let cold = cold_started.elapsed();
111 let mut samples = Vec::with_capacity(MATCH_SAMPLES);
112 for _ in 0..MATCH_SAMPLES {
113 let started = Instant::now();
114 let mut registry = Registry::load(std::slice::from_ref(&request))?;
115 let selection = registry.select(black_box(&arguments))?;
116 if !matches!(selection, Selection::Reduce(_)) {
117 return Err("external benchmark command was not selected".to_owned());
118 }
119 samples.push(started.elapsed());
120 }
121 Ok((cold, p95(samples), body.len()))
122}Trait Implementations§
Source§impl Clone for SourcePack
impl Clone for SourcePack
Source§fn clone(&self) -> SourcePack
fn clone(&self) -> SourcePack
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SourcePack
impl RefUnwindSafe for SourcePack
impl Send for SourcePack
impl Sync for SourcePack
impl Unpin for SourcePack
impl UnsafeUnpin for SourcePack
impl UnwindSafe for SourcePack
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more