azure_core 1.1.0

Rust wrappers around Microsoft Azure REST APIs - Core crate
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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

use azure_core::{json, time::OffsetDateTime, xml};
use criterion::{criterion_group, criterion_main, Criterion};
use models::ListBlobsFlatSegmentResponse;
use std::hint::black_box;

use crate::models::{
    AccessTier, BlobItemInternal, BlobName, BlobPropertiesInternal, BlobType, LeaseState,
    LeaseStatus,
};

const ITEM_COUNT: [usize; 3] = [5, 25, 100];

fn deserialize_list_blobs(c: &mut Criterion) {
    for count in ITEM_COUNT {
        // Generate JSON and XML blobs that emulate `azure_storage_blob::BlobContainerClient::list_blobs()`.
        let mut blobs = ListBlobsFlatSegmentResponse {
            service_endpoint: Some("https://t0123456789abcdefprim.blob.core.windows.net/".into()),
            container_name: Some("container01234567".into()),
            ..Default::default()
        };

        let now = OffsetDateTime::now_utc();
        for i in 0..count {
            let blob = BlobItemInternal {
                name: Some(BlobName {
                    content: Some(format!("testBlob{i}")),
                    ..Default::default()
                }),
                properties: Some(BlobPropertiesInternal {
                    creation_time: Some(now),
                    last_modified: Some(now),
                    etag: Some(format!("{i:#15x}")),
                    content_length: Some(17),
                    content_type: Some("application/x-octet-stream".into()),
                    content_md5: Some([i as u8].to_vec()),
                    blob_type: Some(BlobType::BlockBlob),
                    access_tier: Some(AccessTier::Hot),
                    access_tier_inferred: Some(true),
                    lease_status: Some(LeaseStatus::Unlocked),
                    lease_state: Some(LeaseState::Available),
                    server_encrypted: Some(true),
                    ..Default::default()
                }),
                ..Default::default()
            };
            blobs.segment.blob_items.push(blob);
        }

        let blobs_json = json::to_json(&blobs).expect("serialize json");
        let blobs_xml = xml::to_xml(&blobs).expect("serialize xml");

        let mut group = c.benchmark_group(format!("deserialize_list_blobs/{count}"));
        group.bench_function("json", |b| {
            b.iter(|| {
                let _: ListBlobsFlatSegmentResponse =
                    black_box(json::from_json(&blobs_json).expect("deserialize json"));
            });
        });
        group.bench_function("xml", |b| {
            b.iter(|| {
                let _: ListBlobsFlatSegmentResponse =
                    black_box(xml::from_xml(&blobs_xml).expect("deserialize xml"));
            });
        });
        group.finish();
    }
}

criterion_group! {
    name = benchmarks;
    config = Criterion::default();
    targets = deserialize_list_blobs
}

criterion_main!(benchmarks);

mod models {
    //! Copied from `azure_storage_blob::models`.
    //!
    //! Model definitions remain intact but some unused fields are replaced with `azure_core::Value`
    //! because we still want to retain the same behavior and performance of the deserialization visitor.

    use azure_core::{
        error::{Error, ErrorKind},
        time::OffsetDateTime,
        Value,
    };
    use serde::{Deserialize, Deserializer, Serialize, Serializer};
    use std::{convert::Infallible, str::FromStr};

    /// An enumeration of blobs.
    #[derive(Clone, Default, Deserialize, Debug, Serialize)]
    #[non_exhaustive]
    #[serde(rename = "EnumerationResults")]
    pub struct ListBlobsFlatSegmentResponse {
        /// The container name.
        #[serde(rename = "@ContainerName", skip_serializing_if = "Option::is_none")]
        pub container_name: Option<String>,

        /// The marker of the blobs.
        #[serde(rename = "Marker", skip_serializing_if = "Option::is_none")]
        pub marker: Option<String>,

        /// The max results of the blobs.
        #[serde(rename = "MaxResults", skip_serializing_if = "Option::is_none")]
        pub max_results: Option<i32>,

        /// The next marker of the blobs.
        #[serde(rename = "NextMarker", skip_serializing_if = "Option::is_none")]
        pub next_marker: Option<String>,

        /// The prefix of the blobs.
        #[serde(rename = "Prefix", skip_serializing_if = "Option::is_none")]
        pub prefix: Option<String>,

        /// The blob segment.
        #[serde(default, rename = "Blobs")]
        pub segment: BlobFlatListSegment,

        /// The service endpoint.
        #[serde(rename = "@ServiceEndpoint", skip_serializing_if = "Option::is_none")]
        pub service_endpoint: Option<String>,
    }

    /// The blob flat list segment.
    #[derive(Clone, Default, Deserialize, Debug, Serialize)]
    #[non_exhaustive]
    pub struct BlobFlatListSegment {
        /// The blob items.
        #[serde(default, rename = "Blob")]
        pub blob_items: Vec<BlobItemInternal>,
    }

    /// An Azure Storage Blob
    #[derive(Clone, Default, Deserialize, Debug, Serialize)]
    #[non_exhaustive]
    #[serde(rename = "Blob")]
    pub struct BlobItemInternal {
        /// The tags of the blob.
        #[serde(rename = "BlobTags", skip_serializing_if = "Option::is_none")]
        pub blob_tags: Option<Value>,

        /// Whether the blob is deleted.
        #[serde(rename = "Deleted", skip_serializing_if = "Option::is_none")]
        pub deleted: Option<bool>,

        /// Whether the blob has versions only.
        #[serde(rename = "HasVersionsOnly", skip_serializing_if = "Option::is_none")]
        pub has_versions_only: Option<bool>,

        /// Whether the blob is the current version.
        #[serde(rename = "IsCurrentVersion", skip_serializing_if = "Option::is_none")]
        pub is_current_version: Option<bool>,

        /// The metadata of the blob.
        #[serde(rename = "Metadata", skip_serializing_if = "Option::is_none")]
        pub metadata: Option<Value>,

        /// The name of the blob.
        #[serde(rename = "Name", skip_serializing_if = "Option::is_none")]
        pub name: Option<BlobName>,

        /// The object replication metadata of the blob.
        #[serde(rename = "OrMetadata", skip_serializing_if = "Option::is_none")]
        pub object_replication_metadata: Option<Value>,

        /// The properties of the blob.
        #[serde(rename = "Properties", skip_serializing_if = "Option::is_none")]
        pub properties: Option<BlobPropertiesInternal>,

        /// The snapshot of the blob.
        #[serde(rename = "Snapshot", skip_serializing_if = "Option::is_none")]
        pub snapshot: Option<String>,

        /// The version id of the blob.
        #[serde(rename = "VersionId", skip_serializing_if = "Option::is_none")]
        pub version_id: Option<String>,
    }

    /// The properties of a blob.
    #[derive(Clone, Default, Deserialize, Debug, Serialize)]
    #[non_exhaustive]
    #[serde(rename = "Properties")]
    pub struct BlobPropertiesInternal {
        /// The access tier of the blob.
        #[serde(rename = "AccessTier", skip_serializing_if = "Option::is_none")]
        pub access_tier: Option<AccessTier>,

        /// The access tier change time of the blob.
        #[serde(
            default,
            rename = "AccessTierChangeTime",
            skip_serializing_if = "Option::is_none",
            with = "azure_core::time::rfc7231::option"
        )]
        pub access_tier_change_time: Option<OffsetDateTime>,

        /// Whether the access tier is inferred.
        #[serde(rename = "AccessTierInferred", skip_serializing_if = "Option::is_none")]
        pub access_tier_inferred: Option<bool>,

        /// The archive status of the blob.
        #[serde(rename = "ArchiveStatus", skip_serializing_if = "Option::is_none")]
        pub archive_status: Option<Value>,

        /// The sequence number of the blob.
        #[serde(
            rename = "x-ms-blob-sequence-number",
            skip_serializing_if = "Option::is_none"
        )]
        pub blob_sequence_number: Option<i64>,

        /// The blob type.
        #[serde(rename = "BlobType", skip_serializing_if = "Option::is_none")]
        pub blob_type: Option<BlobType>,

        /// The cache control of the blob.
        #[serde(rename = "Cache-Control", skip_serializing_if = "Option::is_none")]
        pub cache_control: Option<String>,

        /// The content disposition of the blob.
        #[serde(
            rename = "Content-Disposition",
            skip_serializing_if = "Option::is_none"
        )]
        pub content_disposition: Option<String>,

        /// The content encoding of the blob.
        #[serde(rename = "Content-Encoding", skip_serializing_if = "Option::is_none")]
        pub content_encoding: Option<String>,

        /// The content language of the blob.
        #[serde(rename = "Content-Language", skip_serializing_if = "Option::is_none")]
        pub content_language: Option<String>,

        /// The content length of the blob.
        #[serde(rename = "Content-Length", skip_serializing_if = "Option::is_none")]
        pub content_length: Option<u64>,

        /// The content MD5 of the blob.
        #[serde(
            default,
            deserialize_with = "azure_core::base64::option::deserialize",
            rename = "Content-MD5",
            serialize_with = "azure_core::base64::option::serialize",
            skip_serializing_if = "Option::is_none"
        )]
        pub content_md5: Option<Vec<u8>>,

        /// The content type of the blob.
        #[serde(rename = "Content-Type", skip_serializing_if = "Option::is_none")]
        pub content_type: Option<String>,

        /// The copy completion time of the blob.
        #[serde(
            default,
            rename = "CopyCompletionTime",
            skip_serializing_if = "Option::is_none",
            with = "azure_core::time::rfc7231::option"
        )]
        pub copy_completion_time: Option<OffsetDateTime>,

        /// The copy ID of the blob.
        #[serde(rename = "CopyId", skip_serializing_if = "Option::is_none")]
        pub copy_id: Option<String>,

        /// The copy progress of the blob.
        #[serde(rename = "CopyProgress", skip_serializing_if = "Option::is_none")]
        pub copy_progress: Option<String>,

        /// The copy source of the blob.
        #[serde(rename = "CopySource", skip_serializing_if = "Option::is_none")]
        pub copy_source: Option<String>,

        /// The copy status of the blob.
        #[serde(rename = "CopyStatus", skip_serializing_if = "Option::is_none")]
        pub copy_status: Option<Value>,

        /// The copy status description of the blob.
        #[serde(
            rename = "CopyStatusDescription",
            skip_serializing_if = "Option::is_none"
        )]
        pub copy_status_description: Option<String>,

        /// The date-time the blob was created in RFC1123 format.
        #[serde(
            default,
            rename = "Creation-Time",
            skip_serializing_if = "Option::is_none",
            with = "azure_core::time::rfc7231::option"
        )]
        pub creation_time: Option<OffsetDateTime>,

        /// Customer provided key sha256
        #[serde(
            rename = "CustomerProvidedKeySha256",
            skip_serializing_if = "Option::is_none"
        )]
        pub customer_provided_key_sha256: Option<String>,

        /// The time the blob was deleted.
        #[serde(
            default,
            rename = "DeletedTime",
            skip_serializing_if = "Option::is_none",
            with = "azure_core::time::rfc7231::option"
        )]
        pub deleted_time: Option<OffsetDateTime>,

        /// The name of the destination snapshot.
        #[serde(
            rename = "DestinationSnapshot",
            skip_serializing_if = "Option::is_none"
        )]
        pub destination_snapshot: Option<String>,

        /// The encryption scope of the blob.
        #[serde(rename = "EncryptionScope", skip_serializing_if = "Option::is_none")]
        pub encryption_scope: Option<String>,

        /// The blob ETag.
        #[serde(rename = "Etag", skip_serializing_if = "Option::is_none")]
        pub etag: Option<String>,

        /// The expire time of the blob.
        #[serde(
            default,
            rename = "Expiry-Time",
            skip_serializing_if = "Option::is_none",
            with = "azure_core::time::rfc7231::option"
        )]
        pub expires_on: Option<OffsetDateTime>,

        /// The immutability policy until time of the blob.
        #[serde(
            default,
            rename = "ImmutabilityPolicyUntilDate",
            skip_serializing_if = "Option::is_none",
            with = "azure_core::time::rfc7231::option"
        )]
        pub immutability_policy_expires_on: Option<OffsetDateTime>,

        /// The immutability policy mode of the blob.
        #[serde(
            rename = "ImmutabilityPolicyMode",
            skip_serializing_if = "Option::is_none"
        )]
        pub immutability_policy_mode: Option<Value>,

        /// Whether the blob is incremental copy.
        #[serde(rename = "IncrementalCopy", skip_serializing_if = "Option::is_none")]
        pub incremental_copy: Option<bool>,

        /// Whether the blob is sealed.
        #[serde(rename = "Sealed", skip_serializing_if = "Option::is_none")]
        pub is_sealed: Option<bool>,

        /// The last access time of the blob.
        #[serde(
            default,
            rename = "LastAccessTime",
            skip_serializing_if = "Option::is_none",
            with = "azure_core::time::rfc7231::option"
        )]
        pub last_accessed_on: Option<OffsetDateTime>,

        /// The date-time the blob was last modified in RFC1123 format.
        #[serde(
            default,
            rename = "Last-Modified",
            skip_serializing_if = "Option::is_none",
            with = "azure_core::time::rfc7231::option"
        )]
        pub last_modified: Option<OffsetDateTime>,

        /// The lease duration of the blob.
        #[serde(rename = "LeaseDuration", skip_serializing_if = "Option::is_none")]
        pub lease_duration: Option<Value>,

        /// The lease state of the blob.
        #[serde(rename = "LeaseState", skip_serializing_if = "Option::is_none")]
        pub lease_state: Option<LeaseState>,

        /// The lease status of the blob.
        #[serde(rename = "LeaseStatus", skip_serializing_if = "Option::is_none")]
        pub lease_status: Option<LeaseStatus>,

        /// Whether the blob is under legal hold.
        #[serde(rename = "LegalHold", skip_serializing_if = "Option::is_none")]
        pub legal_hold: Option<bool>,

        /// The rehydrate priority of the blob.
        #[serde(rename = "RehydratePriority", skip_serializing_if = "Option::is_none")]
        pub rehydrate_priority: Option<Value>,

        /// The remaining retention days of the blob.
        #[serde(
            rename = "RemainingRetentionDays",
            skip_serializing_if = "Option::is_none"
        )]
        pub remaining_retention_days: Option<i32>,

        /// Whether the blob is encrypted on the server.
        #[serde(rename = "ServerEncrypted", skip_serializing_if = "Option::is_none")]
        pub server_encrypted: Option<bool>,

        /// The number of tags for the blob.
        #[serde(rename = "TagCount", skip_serializing_if = "Option::is_none")]
        pub tag_count: Option<i32>,
    }

    /// The access tiers.
    #[derive(Debug, PartialEq, Eq, Clone)]
    #[non_exhaustive]
    pub enum AccessTier {
        /// The archive access tier.
        Archive,

        /// The Cold access tier.
        Cold,

        /// The cool access tier.
        Cool,

        /// The hot access tier.
        Hot,

        /// The hot P10 tier.
        P10,

        /// The hot P15 tier.
        P15,

        /// The hot P20 tier.
        P20,

        /// The hot P30 tier.
        P30,

        /// The hot P4 tier.
        P4,

        /// The hot P40 tier.
        P40,

        /// The hot P50 tier.
        P50,

        /// The hot P6 tier.
        P6,

        /// The hot P60 tier.
        P60,

        /// The hot P70 tier.
        P70,

        /// The hot P80 tier.
        P80,

        /// The Premium access tier.
        Premium,

        /// Any other value not defined in `AccessTier`.
        UnknownValue(String),
    }

    impl FromStr for AccessTier {
        type Err = Infallible;
        fn from_str(s: &str) -> ::core::result::Result<Self, <Self as FromStr>::Err> {
            Ok(match s {
                "Archive" => AccessTier::Archive,
                "Cold" => AccessTier::Cold,
                "Cool" => AccessTier::Cool,
                "Hot" => AccessTier::Hot,
                "P10" => AccessTier::P10,
                "P15" => AccessTier::P15,
                "P20" => AccessTier::P20,
                "P30" => AccessTier::P30,
                "P4" => AccessTier::P4,
                "P40" => AccessTier::P40,
                "P50" => AccessTier::P50,
                "P6" => AccessTier::P6,
                "P60" => AccessTier::P60,
                "P70" => AccessTier::P70,
                "P80" => AccessTier::P80,
                "Premium" => AccessTier::Premium,
                _ => AccessTier::UnknownValue(s.to_string()),
            })
        }
    }

    impl AsRef<str> for AccessTier {
        fn as_ref(&self) -> &str {
            match self {
                AccessTier::Archive => "Archive",
                AccessTier::Cold => "Cold",
                AccessTier::Cool => "Cool",
                AccessTier::Hot => "Hot",
                AccessTier::P10 => "P10",
                AccessTier::P15 => "P15",
                AccessTier::P20 => "P20",
                AccessTier::P30 => "P30",
                AccessTier::P4 => "P4",
                AccessTier::P40 => "P40",
                AccessTier::P50 => "P50",
                AccessTier::P6 => "P6",
                AccessTier::P60 => "P60",
                AccessTier::P70 => "P70",
                AccessTier::P80 => "P80",
                AccessTier::Premium => "Premium",
                AccessTier::UnknownValue(s) => s.as_str(),
            }
        }
    }

    impl<'de> Deserialize<'de> for AccessTier {
        fn deserialize<D>(deserializer: D) -> ::core::result::Result<Self, D::Error>
        where
            D: Deserializer<'de>,
        {
            let s = String::deserialize(deserializer)?;
            s.parse().map_err(serde::de::Error::custom)
        }
    }

    impl Serialize for AccessTier {
        fn serialize<S>(&self, s: S) -> ::core::result::Result<S::Ok, S::Error>
        where
            S: Serializer,
        {
            s.serialize_str(self.as_ref())
        }
    }

    /// The blob type.
    #[derive(Debug, PartialEq, Eq, Clone, Copy)]
    #[allow(clippy::enum_variant_names)]
    #[non_exhaustive]
    pub enum BlobType {
        /// The blob is an append blob.
        AppendBlob,

        /// The blob is a block blob.
        BlockBlob,

        /// The blob is a page blob.
        PageBlob,
    }

    impl FromStr for BlobType {
        type Err = Error;
        fn from_str(s: &str) -> ::core::result::Result<Self, <Self as FromStr>::Err> {
            Ok(match s {
                "AppendBlob" => BlobType::AppendBlob,
                "BlockBlob" => BlobType::BlockBlob,
                "PageBlob" => BlobType::PageBlob,
                _ => {
                    return Err(Error::with_message_fn(ErrorKind::DataConversion, || {
                        format!("unknown variant of BlobType found: \"{s}\"")
                    }))
                }
            })
        }
    }

    impl AsRef<str> for BlobType {
        fn as_ref(&self) -> &str {
            match self {
                BlobType::AppendBlob => "AppendBlob",
                BlobType::BlockBlob => "BlockBlob",
                BlobType::PageBlob => "PageBlob",
            }
        }
    }

    impl<'de> Deserialize<'de> for BlobType {
        fn deserialize<D>(deserializer: D) -> ::core::result::Result<Self, D::Error>
        where
            D: Deserializer<'de>,
        {
            let s = String::deserialize(deserializer)?;
            s.parse().map_err(serde::de::Error::custom)
        }
    }

    impl Serialize for BlobType {
        fn serialize<S>(&self, s: S) -> ::core::result::Result<S::Ok, S::Error>
        where
            S: Serializer,
        {
            s.serialize_str(self.as_ref())
        }
    }

    /// Represents a blob name.
    #[derive(Clone, Default, Deserialize, Debug, Serialize)]
    #[non_exhaustive]
    pub struct BlobName {
        /// The blob name.
        #[serde(rename = "$text", skip_serializing_if = "Option::is_none")]
        pub content: Option<String>,

        /// Whether the blob name is encoded.
        #[serde(rename = "@Encoded", skip_serializing_if = "Option::is_none")]
        pub encoded: Option<bool>,
    }

    /// The lease state.
    #[derive(Debug, PartialEq, Eq, Clone, Copy)]
    #[non_exhaustive]
    pub enum LeaseState {
        /// The lease is available.
        Available,

        /// The lease is breaking.
        Breaking,

        /// The lease is broken.
        Broken,

        /// The lease is expired.
        Expired,

        /// The lease is currently leased.
        Leased,
    }

    impl FromStr for LeaseState {
        type Err = Error;
        fn from_str(s: &str) -> ::core::result::Result<Self, <Self as FromStr>::Err> {
            Ok(match s {
                "available" => LeaseState::Available,
                "breaking" => LeaseState::Breaking,
                "broken" => LeaseState::Broken,
                "expired" => LeaseState::Expired,
                "leased" => LeaseState::Leased,
                _ => {
                    return Err(Error::with_message_fn(ErrorKind::DataConversion, || {
                        format!("unknown variant of LeaseState found: \"{s}\"")
                    }))
                }
            })
        }
    }

    impl AsRef<str> for LeaseState {
        fn as_ref(&self) -> &str {
            match self {
                LeaseState::Available => "available",
                LeaseState::Breaking => "breaking",
                LeaseState::Broken => "broken",
                LeaseState::Expired => "expired",
                LeaseState::Leased => "leased",
            }
        }
    }

    impl<'de> Deserialize<'de> for LeaseState {
        fn deserialize<D>(deserializer: D) -> ::core::result::Result<Self, D::Error>
        where
            D: Deserializer<'de>,
        {
            let s = String::deserialize(deserializer)?;
            s.parse().map_err(serde::de::Error::custom)
        }
    }

    impl Serialize for LeaseState {
        fn serialize<S>(&self, s: S) -> ::core::result::Result<S::Ok, S::Error>
        where
            S: Serializer,
        {
            s.serialize_str(self.as_ref())
        }
    }

    /// The lease status.
    #[derive(Debug, PartialEq, Eq, Clone, Copy)]
    #[non_exhaustive]
    pub enum LeaseStatus {
        /// The lease is locked.
        Locked,

        /// The lease is unlocked.
        Unlocked,
    }

    impl FromStr for LeaseStatus {
        type Err = Error;
        fn from_str(s: &str) -> ::core::result::Result<Self, <Self as FromStr>::Err> {
            Ok(match s {
                "locked" => LeaseStatus::Locked,
                "unlocked" => LeaseStatus::Unlocked,
                _ => {
                    return Err(Error::with_message_fn(ErrorKind::DataConversion, || {
                        format!("unknown variant of LeaseStatus found: \"{s}\"")
                    }))
                }
            })
        }
    }

    impl AsRef<str> for LeaseStatus {
        fn as_ref(&self) -> &str {
            match self {
                LeaseStatus::Locked => "locked",
                LeaseStatus::Unlocked => "unlocked",
            }
        }
    }

    impl<'de> Deserialize<'de> for LeaseStatus {
        fn deserialize<D>(deserializer: D) -> ::core::result::Result<Self, D::Error>
        where
            D: Deserializer<'de>,
        {
            let s = String::deserialize(deserializer)?;
            s.parse().map_err(serde::de::Error::custom)
        }
    }

    impl Serialize for LeaseStatus {
        fn serialize<S>(&self, s: S) -> ::core::result::Result<S::Ok, S::Error>
        where
            S: Serializer,
        {
            s.serialize_str(self.as_ref())
        }
    }
}