futuresdr/runtime/
block_meta.rs

1/// Block metadata
2pub struct BlockMeta {
3    type_name: String,
4    instance_name: Option<String>,
5    blocking: bool,
6}
7
8impl BlockMeta {
9    fn new(type_name: String, blocking: bool) -> BlockMeta {
10        BlockMeta {
11            type_name,
12            instance_name: None,
13            blocking,
14        }
15    }
16    /// Name of block type
17    pub fn type_name(&self) -> &str {
18        &self.type_name
19    }
20    /// Instance name
21    pub fn instance_name(&self) -> Option<&str> {
22        self.instance_name.as_ref().map(|x| x as _)
23    }
24    /// Set instance name
25    pub fn set_instance_name(&mut self, name: impl Into<String>) {
26        self.instance_name = Some(name.into());
27    }
28    /// Is block blocking
29    ///
30    /// Blocking blocks will be spawned on a separate thread.
31    pub fn is_blocking(&self) -> bool {
32        self.blocking
33    }
34}
35
36/// Block metadata buidler
37pub struct BlockMetaBuilder {
38    name: String,
39    blocking: bool,
40}
41
42impl BlockMetaBuilder {
43    /// Create builder
44    pub fn new(name: impl Into<String>) -> BlockMetaBuilder {
45        BlockMetaBuilder {
46            name: name.into(),
47            blocking: false,
48        }
49    }
50    /// Mark block as blocking
51    ///
52    /// Blocking blocks will be spawned on a separate thread.
53    #[must_use]
54    pub fn blocking(mut self) -> Self {
55        self.blocking = true;
56        self
57    }
58    /// Build block metadata
59    pub fn build(self) -> BlockMeta {
60        BlockMeta::new(self.name, self.blocking)
61    }
62}