ocpp-kit 0.5.0

Open Charge Point Protocol (OCPP 1.6J, 2.0.1, 2.1) toolkit for Rust: typed messages, OCPP-J framing, a sans-I/O protocol engine, and transports for charging stations, CSMS and local controllers.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
// @generated by `cargo xtask codegen` from the vendored OCPP JSON schemas.
// DO NOT EDIT — re-run the generator instead. CI fails if this file is stale.

//! Data types shared between OCPP 1.6 messages, generated from the official JSON schemas.

#![allow(unused_imports, clippy::doc_markdown, clippy::struct_excessive_bools)]
#![allow(
    clippy::too_many_lines,
    clippy::too_many_arguments,
    clippy::wildcard_imports
)]
#![allow(clippy::match_same_arms, clippy::fn_params_excessive_bools)]

use alloc::string::String;
use alloc::vec::Vec;

use serde::{Deserialize, Serialize};

use super::enums::*;
use crate::validate::{self, Validate, ValidationPath, Violations};

/// The OCPP 1.6 `AuthorizationData` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct AuthorizationData {
    /// The `idTag` member.
    #[serde(rename = "idTag")]
    pub id_tag: String,
    /// The `idTagInfo` member.
    #[serde(rename = "idTagInfo")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub id_tag_info: Option<IdTagInfo>,
}

impl AuthorizationData {
    /// Creates a `AuthorizationData` from its required fields.
    #[must_use]
    pub fn new(id_tag: impl Into<String>) -> Self {
        Self {
            id_tag: id_tag.into(),
            id_tag_info: None,
        }
    }

    /// Sets the optional `idTagInfo` field.
    #[must_use]
    pub fn with_id_tag_info(mut self, value: IdTagInfo) -> Self {
        self.id_tag_info = Some(value);
        self
    }
}

impl Validate for AuthorizationData {
    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
        path.push_key("idTag");
        validate::string(self.id_tag.as_str(), None, Some(20), path, out);
        path.pop();
        path.push_key("idTagInfo");
        if let Some(value) = &self.id_tag_info {
            Validate::validate_at(value, path, out);
        }
        path.pop();
    }
}

/// The OCPP 1.6 `CertificateHashData` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CertificateHashData {
    /// The `hashAlgorithm` member.
    #[serde(rename = "hashAlgorithm")]
    pub hash_algorithm: HashAlgorithm,
    /// The `issuerNameHash` member.
    #[serde(rename = "issuerNameHash")]
    pub issuer_name_hash: String,
    /// The `issuerKeyHash` member.
    #[serde(rename = "issuerKeyHash")]
    pub issuer_key_hash: String,
    /// The `serialNumber` member.
    #[serde(rename = "serialNumber")]
    pub serial_number: String,
}

impl CertificateHashData {
    /// Creates a `CertificateHashData` from its required fields.
    #[must_use]
    pub fn new(
        hash_algorithm: HashAlgorithm,
        issuer_name_hash: impl Into<String>,
        issuer_key_hash: impl Into<String>,
        serial_number: impl Into<String>,
    ) -> Self {
        Self {
            hash_algorithm,
            issuer_name_hash: issuer_name_hash.into(),
            issuer_key_hash: issuer_key_hash.into(),
            serial_number: serial_number.into(),
        }
    }
}

impl Validate for CertificateHashData {
    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
        path.push_key("hashAlgorithm");
        Validate::validate_at(&self.hash_algorithm, path, out);
        path.pop();
        path.push_key("issuerNameHash");
        validate::string(self.issuer_name_hash.as_str(), None, Some(128), path, out);
        path.pop();
        path.push_key("issuerKeyHash");
        validate::string(self.issuer_key_hash.as_str(), None, Some(128), path, out);
        path.pop();
        path.push_key("serialNumber");
        validate::string(self.serial_number.as_str(), None, Some(40), path, out);
        path.pop();
    }
}

/// The OCPP 1.6 `ChargingProfile` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ChargingProfile {
    /// The `chargingProfileId` member.
    #[serde(rename = "chargingProfileId")]
    pub charging_profile_id: i32,
    /// The `stackLevel` member.
    #[serde(rename = "stackLevel")]
    pub stack_level: i32,
    /// The `chargingProfilePurpose` member.
    #[serde(rename = "chargingProfilePurpose")]
    pub charging_profile_purpose: ChargingProfilePurpose,
    /// The `chargingProfileKind` member.
    #[serde(rename = "chargingProfileKind")]
    pub charging_profile_kind: ChargingProfileKind,
    /// The `chargingSchedule` member.
    #[serde(rename = "chargingSchedule")]
    pub charging_schedule: ChargingSchedule,
    /// The `transactionId` member.
    #[serde(rename = "transactionId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub transaction_id: Option<i32>,
    /// The `recurrencyKind` member.
    #[serde(rename = "recurrencyKind")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub recurrency_kind: Option<RecurrencyKind>,
    /// The `validFrom` member.
    #[serde(rename = "validFrom")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub valid_from: Option<crate::types::DateTime>,
    /// The `validTo` member.
    #[serde(rename = "validTo")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub valid_to: Option<crate::types::DateTime>,
}

impl ChargingProfile {
    /// Creates a `ChargingProfile` from its required fields.
    #[must_use]
    pub fn new(
        charging_profile_id: i32,
        stack_level: i32,
        charging_profile_purpose: ChargingProfilePurpose,
        charging_profile_kind: ChargingProfileKind,
        charging_schedule: ChargingSchedule,
    ) -> Self {
        Self {
            charging_profile_id,
            stack_level,
            charging_profile_purpose,
            charging_profile_kind,
            charging_schedule,
            transaction_id: None,
            recurrency_kind: None,
            valid_from: None,
            valid_to: None,
        }
    }

    /// Sets the optional `transactionId` field.
    #[must_use]
    pub fn with_transaction_id(mut self, value: i32) -> Self {
        self.transaction_id = Some(value);
        self
    }

    /// Sets the optional `recurrencyKind` field.
    #[must_use]
    pub fn with_recurrency_kind(mut self, value: RecurrencyKind) -> Self {
        self.recurrency_kind = Some(value);
        self
    }

    /// Sets the optional `validFrom` field.
    #[must_use]
    pub fn with_valid_from(mut self, value: impl Into<crate::types::DateTime>) -> Self {
        self.valid_from = Some(value.into());
        self
    }

    /// Sets the optional `validTo` field.
    #[must_use]
    pub fn with_valid_to(mut self, value: impl Into<crate::types::DateTime>) -> Self {
        self.valid_to = Some(value.into());
        self
    }
}

impl Validate for ChargingProfile {
    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
        path.push_key("chargingProfilePurpose");
        Validate::validate_at(&self.charging_profile_purpose, path, out);
        path.pop();
        path.push_key("chargingProfileKind");
        Validate::validate_at(&self.charging_profile_kind, path, out);
        path.pop();
        path.push_key("chargingSchedule");
        Validate::validate_at(&self.charging_schedule, path, out);
        path.pop();
        path.push_key("recurrencyKind");
        if let Some(value) = &self.recurrency_kind {
            Validate::validate_at(value, path, out);
        }
        path.pop();
    }
}

/// The OCPP 1.6 `ChargingSchedule` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ChargingSchedule {
    /// The `chargingRateUnit` member.
    #[serde(rename = "chargingRateUnit")]
    pub charging_rate_unit: ChargingRateUnit,
    /// The `chargingSchedulePeriod` member.
    #[serde(rename = "chargingSchedulePeriod")]
    pub charging_schedule_period: Vec<ChargingSchedulePeriod>,
    /// The `duration` member.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub duration: Option<i32>,
    /// The `startSchedule` member.
    #[serde(rename = "startSchedule")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub start_schedule: Option<crate::types::DateTime>,
    /// The `minChargingRate` member.
    #[serde(rename = "minChargingRate")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub min_charging_rate: Option<crate::types::Decimal>,
}

impl ChargingSchedule {
    /// Creates a `ChargingSchedule` from its required fields.
    #[must_use]
    pub fn new(
        charging_rate_unit: ChargingRateUnit,
        charging_schedule_period: Vec<ChargingSchedulePeriod>,
    ) -> Self {
        Self {
            charging_rate_unit,
            charging_schedule_period,
            duration: None,
            start_schedule: None,
            min_charging_rate: None,
        }
    }

    /// Sets the optional `duration` field.
    #[must_use]
    pub fn with_duration(mut self, value: i32) -> Self {
        self.duration = Some(value);
        self
    }

    /// Sets the optional `startSchedule` field.
    #[must_use]
    pub fn with_start_schedule(mut self, value: impl Into<crate::types::DateTime>) -> Self {
        self.start_schedule = Some(value.into());
        self
    }

    /// Sets the optional `minChargingRate` field.
    #[must_use]
    pub fn with_min_charging_rate(mut self, value: impl Into<crate::types::Decimal>) -> Self {
        self.min_charging_rate = Some(value.into());
        self
    }
}

impl Validate for ChargingSchedule {
    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
        path.push_key("chargingRateUnit");
        Validate::validate_at(&self.charging_rate_unit, path, out);
        path.pop();
        path.push_key("chargingSchedulePeriod");
        for (index, item) in self.charging_schedule_period.iter().enumerate() {
            path.push_index(index);
            Validate::validate_at(item, path, out);
            path.pop();
        }
        path.pop();
    }
}

/// The OCPP 1.6 `ChargingSchedulePeriod` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ChargingSchedulePeriod {
    /// The `startPeriod` member.
    #[serde(rename = "startPeriod")]
    pub start_period: i32,
    /// The `limit` member.
    pub limit: crate::types::Decimal,
    /// The `numberPhases` member.
    #[serde(rename = "numberPhases")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub number_phases: Option<i32>,
}

impl ChargingSchedulePeriod {
    /// Creates a `ChargingSchedulePeriod` from its required fields.
    #[must_use]
    pub fn new(start_period: i32, limit: impl Into<crate::types::Decimal>) -> Self {
        Self {
            start_period,
            limit: limit.into(),
            number_phases: None,
        }
    }

    /// Sets the optional `numberPhases` field.
    #[must_use]
    pub fn with_number_phases(mut self, value: i32) -> Self {
        self.number_phases = Some(value);
        self
    }
}

impl Validate for ChargingSchedulePeriod {
    fn validate_at(&self, _path: &mut ValidationPath, _out: &mut Violations) {}
}

/// The OCPP 1.6 `Firmware` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Firmware {
    /// The `location` member.
    pub location: String,
    /// The `retrieveDateTime` member.
    #[serde(rename = "retrieveDateTime")]
    pub retrieve_date_time: crate::types::DateTime,
    /// The `signingCertificate` member.
    #[serde(rename = "signingCertificate")]
    pub signing_certificate: String,
    /// The `signature` member.
    pub signature: String,
    /// The `installDateTime` member.
    #[serde(rename = "installDateTime")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub install_date_time: Option<crate::types::DateTime>,
}

impl Firmware {
    /// Creates a `Firmware` from its required fields.
    #[must_use]
    pub fn new(
        location: impl Into<String>,
        retrieve_date_time: impl Into<crate::types::DateTime>,
        signing_certificate: impl Into<String>,
        signature: impl Into<String>,
    ) -> Self {
        Self {
            location: location.into(),
            retrieve_date_time: retrieve_date_time.into(),
            signing_certificate: signing_certificate.into(),
            signature: signature.into(),
            install_date_time: None,
        }
    }

    /// Sets the optional `installDateTime` field.
    #[must_use]
    pub fn with_install_date_time(mut self, value: impl Into<crate::types::DateTime>) -> Self {
        self.install_date_time = Some(value.into());
        self
    }
}

impl Validate for Firmware {
    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
        path.push_key("location");
        validate::string(self.location.as_str(), None, Some(512), path, out);
        path.pop();
        path.push_key("signingCertificate");
        validate::string(
            self.signing_certificate.as_str(),
            None,
            Some(5500),
            path,
            out,
        );
        path.pop();
        path.push_key("signature");
        validate::string(self.signature.as_str(), None, Some(800), path, out);
        path.pop();
    }
}

/// The OCPP 1.6 `IdTagInfo` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct IdTagInfo {
    /// The `status` member.
    pub status: AuthorizationStatus,
    /// The `expiryDate` member.
    #[serde(rename = "expiryDate")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub expiry_date: Option<crate::types::DateTime>,
    /// The `parentIdTag` member.
    #[serde(rename = "parentIdTag")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub parent_id_tag: Option<String>,
}

impl IdTagInfo {
    /// Creates a `IdTagInfo` from its required fields.
    #[must_use]
    pub fn new(status: AuthorizationStatus) -> Self {
        Self {
            status,
            expiry_date: None,
            parent_id_tag: None,
        }
    }

    /// Sets the optional `expiryDate` field.
    #[must_use]
    pub fn with_expiry_date(mut self, value: impl Into<crate::types::DateTime>) -> Self {
        self.expiry_date = Some(value.into());
        self
    }

    /// Sets the optional `parentIdTag` field.
    #[must_use]
    pub fn with_parent_id_tag(mut self, value: impl Into<String>) -> Self {
        self.parent_id_tag = Some(value.into());
        self
    }
}

impl Validate for IdTagInfo {
    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
        path.push_key("status");
        Validate::validate_at(&self.status, path, out);
        path.pop();
        path.push_key("parentIdTag");
        if let Some(value) = &self.parent_id_tag {
            validate::string(value.as_str(), None, Some(20), path, out);
        }
        path.pop();
    }
}

/// The OCPP 1.6 `KeyValue` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct KeyValue {
    /// The `key` member.
    pub key: String,
    /// The `readonly` member.
    pub readonly: bool,
    /// The `value` member.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub value: Option<String>,
}

impl KeyValue {
    /// Creates a `KeyValue` from its required fields.
    #[must_use]
    pub fn new(key: impl Into<String>, readonly: bool) -> Self {
        Self {
            key: key.into(),
            readonly,
            value: None,
        }
    }

    /// Sets the optional `value` field.
    #[must_use]
    pub fn with_value(mut self, value: impl Into<String>) -> Self {
        self.value = Some(value.into());
        self
    }
}

impl Validate for KeyValue {
    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
        path.push_key("key");
        validate::string(self.key.as_str(), None, Some(50), path, out);
        path.pop();
        path.push_key("value");
        if let Some(value) = &self.value {
            validate::string(value.as_str(), None, Some(500), path, out);
        }
        path.pop();
    }
}

/// The OCPP 1.6 `LogParameters` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct LogParameters {
    /// The `remoteLocation` member.
    #[serde(rename = "remoteLocation")]
    pub remote_location: String,
    /// The `oldestTimestamp` member.
    #[serde(rename = "oldestTimestamp")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub oldest_timestamp: Option<crate::types::DateTime>,
    /// The `latestTimestamp` member.
    #[serde(rename = "latestTimestamp")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub latest_timestamp: Option<crate::types::DateTime>,
}

impl LogParameters {
    /// Creates a `LogParameters` from its required fields.
    #[must_use]
    pub fn new(remote_location: impl Into<String>) -> Self {
        Self {
            remote_location: remote_location.into(),
            oldest_timestamp: None,
            latest_timestamp: None,
        }
    }

    /// Sets the optional `oldestTimestamp` field.
    #[must_use]
    pub fn with_oldest_timestamp(mut self, value: impl Into<crate::types::DateTime>) -> Self {
        self.oldest_timestamp = Some(value.into());
        self
    }

    /// Sets the optional `latestTimestamp` field.
    #[must_use]
    pub fn with_latest_timestamp(mut self, value: impl Into<crate::types::DateTime>) -> Self {
        self.latest_timestamp = Some(value.into());
        self
    }
}

impl Validate for LogParameters {
    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
        path.push_key("remoteLocation");
        validate::string(self.remote_location.as_str(), None, Some(512), path, out);
        path.pop();
    }
}

/// The OCPP 1.6 `MeterValue` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MeterValue {
    /// The `timestamp` member.
    pub timestamp: crate::types::DateTime,
    /// The `sampledValue` member.
    #[serde(rename = "sampledValue")]
    pub sampled_value: Vec<SampledValue>,
}

impl MeterValue {
    /// Creates a `MeterValue` from its required fields.
    #[must_use]
    pub fn new(
        timestamp: impl Into<crate::types::DateTime>,
        sampled_value: Vec<SampledValue>,
    ) -> Self {
        Self {
            timestamp: timestamp.into(),
            sampled_value,
        }
    }
}

impl Validate for MeterValue {
    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
        path.push_key("sampledValue");
        validate::list_len(self.sampled_value.len(), Some(1), None, path, out);
        for (index, item) in self.sampled_value.iter().enumerate() {
            path.push_index(index);
            Validate::validate_at(item, path, out);
            path.pop();
        }
        path.pop();
    }
}

/// The OCPP 1.6 `SampledValue` data type.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct SampledValue {
    /// The `value` member.
    pub value: String,
    /// The `context` member.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub context: Option<ReadingContext>,
    /// The `format` member.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub format: Option<ValueFormat>,
    /// The `measurand` member.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub measurand: Option<Measurand>,
    /// The `phase` member.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub phase: Option<Phase>,
    /// The `location` member.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub location: Option<Location>,
    /// The `unit` member.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub unit: Option<UnitOfMeasure>,
}

impl SampledValue {
    /// Creates a `SampledValue` from its required fields.
    #[must_use]
    pub fn new(value: impl Into<String>) -> Self {
        Self {
            value: value.into(),
            context: None,
            format: None,
            measurand: None,
            phase: None,
            location: None,
            unit: None,
        }
    }

    /// Sets the optional `context` field.
    #[must_use]
    pub fn with_context(mut self, value: ReadingContext) -> Self {
        self.context = Some(value);
        self
    }

    /// Sets the optional `format` field.
    #[must_use]
    pub fn with_format(mut self, value: ValueFormat) -> Self {
        self.format = Some(value);
        self
    }

    /// Sets the optional `measurand` field.
    #[must_use]
    pub fn with_measurand(mut self, value: Measurand) -> Self {
        self.measurand = Some(value);
        self
    }

    /// Sets the optional `phase` field.
    #[must_use]
    pub fn with_phase(mut self, value: Phase) -> Self {
        self.phase = Some(value);
        self
    }

    /// Sets the optional `location` field.
    #[must_use]
    pub fn with_location(mut self, value: Location) -> Self {
        self.location = Some(value);
        self
    }

    /// Sets the optional `unit` field.
    #[must_use]
    pub fn with_unit(mut self, value: UnitOfMeasure) -> Self {
        self.unit = Some(value);
        self
    }
}

impl Validate for SampledValue {
    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
        path.push_key("context");
        if let Some(value) = &self.context {
            Validate::validate_at(value, path, out);
        }
        path.pop();
        path.push_key("format");
        if let Some(value) = &self.format {
            Validate::validate_at(value, path, out);
        }
        path.pop();
        path.push_key("measurand");
        if let Some(value) = &self.measurand {
            Validate::validate_at(value, path, out);
        }
        path.pop();
        path.push_key("phase");
        if let Some(value) = &self.phase {
            Validate::validate_at(value, path, out);
        }
        path.pop();
        path.push_key("location");
        if let Some(value) = &self.location {
            Validate::validate_at(value, path, out);
        }
        path.pop();
        path.push_key("unit");
        if let Some(value) = &self.unit {
            Validate::validate_at(value, path, out);
        }
        path.pop();
    }
}