somatize_fabric_wire/artifact.rs
1//! What an empty worker is provisioned with.
2//!
3//! A generic worker starts **without a catalog**: it knows how to execute plans
4//! and does not know what `tokenize` is. The artifact is what tells it, and this
5//! crate **does not look at what it carries** — that is the
6//! [`Provision`](crate::Provision)'s business. A `cloudpickle` of Python
7//! objects, a zip of a package, or a factory name are the same `bytes` field
8//! with a different `kind`.
9//!
10//! The `id` is set by whoever produces it rather than hashed here: **without
11//! interpreting the content there is no criterion for saying when two artifacts
12//! are the same one**, and two pickles of one catalog can differ byte for byte.
13//! Whoever produces it knows what identifies it and says so; here we compare
14//! strings.
15
16/// What turns an empty worker into one that can execute your graph.
17#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
18pub struct Artifact {
19 /// How it must be interpreted: `pickle`, `package`, `factory`… Text and not
20 /// an enum because the vocabulary belongs to the [`Provision`](crate::Provision).
21 pub kind: String,
22 /// Which one it is, so it is not sent twice. Set by whoever produces it.
23 pub id: String,
24 /// What it is. Nobody here looks at it.
25 pub bytes: Vec<u8>,
26}
27
28impl Artifact {
29 /// An artifact of this kind, with this identity and these bytes.
30 pub fn new(kind: impl Into<String>, id: impl Into<String>, bytes: Vec<u8>) -> Self {
31 Self {
32 kind: kind.into(),
33 id: id.into(),
34 bytes,
35 }
36 }
37
38 /// How it announces itself before being sent: kind and identity, without
39 /// the weight.
40 pub fn label(&self) -> Label {
41 Label {
42 kind: self.kind.clone(),
43 id: self.id.clone(),
44 }
45 }
46}
47
48/// What an artifact is called, without the artifact.
49#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
50pub struct Label {
51 /// How it must be interpreted.
52 pub kind: String,
53 /// Which one it is.
54 pub id: String,
55}