dis_rs/common/attribute/
builder.rs

1use crate::common::attribute::model::{Attribute, AttributeRecordSet};
2use crate::common::model::SimulationAddress;
3use crate::enumerations::{AttributeActionCode, PduType, ProtocolVersion, VariableRecordType};
4
5pub struct AttributeBuilder(Attribute);
6
7impl Default for AttributeBuilder {
8    fn default() -> Self {
9        Self::new()
10    }
11}
12
13impl AttributeBuilder {
14    #[must_use]
15    pub fn new() -> Self {
16        AttributeBuilder(Attribute::default())
17    }
18
19    #[must_use]
20    pub fn new_from_body(body: Attribute) -> Self {
21        AttributeBuilder(body)
22    }
23
24    #[must_use]
25    pub fn build(self) -> Attribute {
26        self.0
27    }
28
29    #[must_use]
30    pub fn with_originating_simulation_address(
31        mut self,
32        originating_simulation_address: SimulationAddress,
33    ) -> Self {
34        self.0.originating_simulation_address = originating_simulation_address;
35        self
36    }
37
38    #[must_use]
39    pub fn with_record_pdu_type(mut self, record_pdu_type: PduType) -> Self {
40        self.0.record_pdu_type = record_pdu_type;
41        self
42    }
43
44    #[must_use]
45    pub fn with_record_protocol_version(
46        mut self,
47        record_protocol_version: ProtocolVersion,
48    ) -> Self {
49        self.0.record_protocol_version = record_protocol_version;
50        self
51    }
52
53    #[must_use]
54    pub fn with_master_attribute_record_type(
55        mut self,
56        master_attribute_record_type: VariableRecordType,
57    ) -> Self {
58        self.0.master_attribute_record_type = master_attribute_record_type;
59        self
60    }
61
62    #[must_use]
63    pub fn with_action_code(mut self, action_code: AttributeActionCode) -> Self {
64        self.0.action_code = action_code;
65        self
66    }
67
68    #[must_use]
69    pub fn with_attribute_record_set(mut self, attribute_record_set: AttributeRecordSet) -> Self {
70        self.0.attribute_record_sets.push(attribute_record_set);
71        self
72    }
73
74    #[must_use]
75    pub fn with_attribute_record_sets(
76        mut self,
77        attribute_record_sets: Vec<AttributeRecordSet>,
78    ) -> Self {
79        self.0.attribute_record_sets = attribute_record_sets;
80        self
81    }
82}