bsp_types/task/
id.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Default, Debug, Serialize, Deserialize, Clone)]
4#[serde(rename_all = "camelCase", default)]
5/// The Task Id allows clients to uniquely identify a BSP task and establish a client-parent
6/// relationship with another task id.
7pub struct TaskId {
8    /// A unique identifier
9    id: String,
10
11    /// The parent task ids, if any. A non-empty parents field means
12    ///  * this task is a sub-task of every parent task id. The child-parent
13    ///  * relationship of tasks makes it possible to render tasks in
14    ///  * a tree-like user interface or inspect what caused a certain task
15    ///  * execution.
16    #[serde(skip_serializing_if = "Vec::is_empty")]
17    parents: Vec<String>,
18}
19
20impl From<String> for TaskId {
21    fn from(id: String) -> Self {
22        Self {
23            id,
24            parents: Default::default(),
25        }
26    }
27}
28
29impl From<&str> for TaskId {
30    fn from(id: &str) -> Self {
31        Self {
32            id: id.into(),
33            parents: Default::default(),
34        }
35    }
36}
37
38impl TaskId {
39    pub fn new(id: String, parents: Vec<String>) -> Self {
40        Self { id, parents }
41    }
42
43    pub fn add_parent(&mut self, value: String) {
44        self.parents.push(value)
45    }
46}