buildkit_rs_llb/op_metadata/
mod.rs1pub mod attr;
2pub mod cap;
3
4use std::collections::HashMap;
5
6use attr::Attr;
7use buildkit_rs_proto::pb;
8
9#[derive(Debug, Clone)]
10pub struct OpMetadata {
11 pub ignore_cache: bool,
12 pub description: HashMap<Attr, String>,
13}
14
15impl OpMetadata {
16 pub fn new() -> Self {
17 Self::default()
18 }
19}
20
21impl Default for OpMetadata {
22 fn default() -> Self {
23 Self {
24 ignore_cache: false,
25 description: HashMap::new(),
26 }
27 }
28}
29
30impl Into<pb::OpMetadata> for OpMetadata {
31 fn into(self) -> pb::OpMetadata {
32 pb::OpMetadata {
33 ignore_cache: self.ignore_cache,
34 description: self
35 .description
36 .into_iter()
37 .map(|(k, v)| (k.into(), v))
38 .collect(),
39 caps: HashMap::new(),
40 export_cache: None,
41 progress_group: None,
42 }
43 }
44}
45
46pub trait OpMetadataBuilder: Sized {
47 fn metadata(&self) -> &OpMetadata;
48 fn metadata_mut(&mut self) -> &mut OpMetadata;
49
50 fn ignore_cache(mut self, ignore: bool) -> Self {
51 self.metadata_mut().ignore_cache = ignore;
52 self
53 }
54
55 fn set_description(mut self, attr: Attr, value: impl AsRef<str>) -> Self {
56 self.metadata_mut()
57 .description
58 .insert(attr, value.as_ref().to_owned());
59 self
60 }
61
62 fn remove_description(mut self, attr: Attr) -> Self {
63 self.metadata_mut().description.remove(&attr);
64 self
65 }
66
67 fn set_custom_name(self, name: impl AsRef<str>) -> Self {
68 self.set_description(Attr::CUSTOM_NAME, name)
69 }
70}