sl-types 0.6.1

Some basic types for Second Life related tools
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
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
//! Second Life key (UUID) related types

use uuid::{Uuid, uuid};

#[cfg(feature = "chumsky")]
use chumsky::{
    IterParser as _, Parser,
    prelude::{just, one_of},
};

/// parse a UUID
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn uuid_parser<'src>()
-> impl Parser<'src, &'src str, uuid::Uuid, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    one_of("0123456789abcdef")
        .repeated()
        .exactly(8)
        .collect::<String>()
        .then_ignore(just('-'))
        .then(
            one_of("0123456789abcdef")
                .repeated()
                .exactly(4)
                .collect::<String>(),
        )
        .then_ignore(just('-'))
        .then(
            one_of("0123456789abcdef")
                .repeated()
                .exactly(4)
                .collect::<String>(),
        )
        .then_ignore(just('-'))
        .then(
            one_of("0123456789abcdef")
                .repeated()
                .exactly(4)
                .collect::<String>(),
        )
        .then_ignore(just('-'))
        .then(
            one_of("0123456789abcdef")
                .repeated()
                .exactly(12)
                .collect::<String>(),
        )
        .try_map(|((((a, b), c), d), e), span: chumsky::span::SimpleSpan| {
            uuid::Uuid::parse_str(&format!("{a}-{b}-{c}-{d}-{e}"))
                .map_err(|e| chumsky::error::Rich::custom(span, format!("{e:?}")))
        })
}

/// represents a general Second Life key without any knowledge about the type
/// of entity this represents
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Key(pub Uuid);

impl std::fmt::Display for Key {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

/// parse a Key
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
#[expect(
    clippy::module_name_repetitions,
    reason = "the parser is going to be used outside this module"
)]
pub fn key_parser<'src>()
-> impl Parser<'src, &'src str, Key, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    uuid_parser().map(Key)
}

/// the null key used by Second Life in many places to represent the absence
/// of a key value
pub const NULL_KEY: Key = Key(uuid!("00000000-0000-0000-0000-000000000000"));

/// the key used by the Second Life system to send combat logs to the COMBAT_CHANNEL
pub const COMBAT_LOG_ID: Key = Key(uuid!("45e0fcfa-2268-4490-a51c-3e51bdfe80d1"));

/// represents a Second Life key for an agent (avatar)
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct AgentKey(pub Key);

impl std::fmt::Display for AgentKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<AgentKey> for Key {
    fn from(val: AgentKey) -> Self {
        val.0
    }
}

/// parse an AgentKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn agent_key_parser<'src>()
-> impl Parser<'src, &'src str, AgentKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    key_parser().map(AgentKey)
}

/// parse a viewer URI that is either an /about or /inspect URL for an avatar
/// and return the AgentKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn app_agent_uri_as_agent_key_parser<'src>()
-> impl Parser<'src, &'src str, AgentKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    crate::viewer_uri::viewer_app_agent_uri_parser().try_map(|uri, span| match uri {
        crate::viewer_uri::ViewerUri::AgentAbout(agent_key)
        | crate::viewer_uri::ViewerUri::AgentInspect(agent_key) => Ok(agent_key),
        _ => Err(chumsky::error::Rich::custom(
            span,
            "Unexpected type of Agent viewer URI",
        )),
    })
}

/// represents a Second Life key for a classified ad
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct ClassifiedKey(pub Key);

impl std::fmt::Display for ClassifiedKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<ClassifiedKey> for Key {
    fn from(val: ClassifiedKey) -> Self {
        val.0
    }
}

/// parse a ClassifiedKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn classified_key_parser<'src>()
-> impl Parser<'src, &'src str, ClassifiedKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>>
{
    key_parser().map(ClassifiedKey)
}

/// represents a Second Life key for an experience
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct ExperienceKey(pub Key);

impl std::fmt::Display for ExperienceKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<ExperienceKey> for Key {
    fn from(val: ExperienceKey) -> Self {
        val.0
    }
}

/// parse an ExperienceKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn experience_key_parser<'src>()
-> impl Parser<'src, &'src str, ExperienceKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>>
{
    key_parser().map(ExperienceKey)
}

/// represents a Second Life key for an agent who is a friend
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct FriendKey(pub Key);

impl std::fmt::Display for FriendKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<FriendKey> for Key {
    fn from(val: FriendKey) -> Self {
        val.0
    }
}

impl From<FriendKey> for AgentKey {
    fn from(val: FriendKey) -> Self {
        Self(val.0)
    }
}

/// parse a FriendKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn friend_key_parser<'src>()
-> impl Parser<'src, &'src str, FriendKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    key_parser().map(FriendKey)
}

/// represents a Second Life key for a group
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct GroupKey(pub Key);

impl std::fmt::Display for GroupKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<GroupKey> for Key {
    fn from(val: GroupKey) -> Self {
        val.0
    }
}

/// parse a GroupKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn group_key_parser<'src>()
-> impl Parser<'src, &'src str, GroupKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    key_parser().map(GroupKey)
}

/// parse a viewer URI that is either an /about or /inspect URL for a group
/// and return the GroupKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn app_group_uri_as_group_key_parser<'src>()
-> impl Parser<'src, &'src str, GroupKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    crate::viewer_uri::viewer_app_group_uri_parser().try_map(|uri, span| match uri {
        crate::viewer_uri::ViewerUri::GroupAbout(group_key)
        | crate::viewer_uri::ViewerUri::GroupInspect(group_key) => Ok(group_key),
        _ => Err(chumsky::error::Rich::custom(
            span,
            "Unexpected type of group viewer URI",
        )),
    })
}

/// represents a Second Life key for an inventory item
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct InventoryKey(pub Key);

impl std::fmt::Display for InventoryKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<InventoryKey> for Key {
    fn from(val: InventoryKey) -> Self {
        val.0
    }
}

/// parse an InventoryKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn inventory_key_parser<'src>()
-> impl Parser<'src, &'src str, InventoryKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>>
{
    key_parser().map(InventoryKey)
}

/// represents a Second Life key for an object
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct ObjectKey(pub Key);

impl std::fmt::Display for ObjectKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<ObjectKey> for Key {
    fn from(val: ObjectKey) -> Self {
        val.0
    }
}

/// parse an ObjectKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn object_key_parser<'src>()
-> impl Parser<'src, &'src str, ObjectKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    key_parser().map(ObjectKey)
}

/// represents a Second Life key for a parcel
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct ParcelKey(pub Key);

impl std::fmt::Display for ParcelKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<ParcelKey> for Key {
    fn from(val: ParcelKey) -> Self {
        val.0
    }
}

/// parse a ParcelKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn parcel_key_parser<'src>()
-> impl Parser<'src, &'src str, ParcelKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    key_parser().map(ParcelKey)
}

/// represents a Second Life key for a texture
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct TextureKey(pub Key);

impl std::fmt::Display for TextureKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<TextureKey> for Key {
    fn from(val: TextureKey) -> Self {
        val.0
    }
}

/// parse a TextureKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn texture_key_parser<'src>()
-> impl Parser<'src, &'src str, TextureKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    key_parser().map(TextureKey)
}

/// represents a Second Life key for an inventory folder
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct InventoryFolderKey(pub Key);

impl std::fmt::Display for InventoryFolderKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<InventoryFolderKey> for Key {
    fn from(val: InventoryFolderKey) -> Self {
        val.0
    }
}

/// parse an InventoryFolderKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn inventory_folder_key_parser<'src>() -> impl Parser<
    'src,
    &'src str,
    InventoryFolderKey,
    chumsky::extra::Err<chumsky::error::Rich<'src, char>>,
> {
    key_parser().map(InventoryFolderKey)
}

/// represents s Second Life key for an owner (e.g. of an object)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum::EnumIs)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub enum OwnerKey {
    /// the owner is an agent
    Agent(AgentKey),
    /// the owner is a group
    Group(GroupKey),
}

// Order by the underlying UUID, not by variant, so the two owner kinds
// interleave in a single key space (an `Agent` and a `Group` sort purely by id,
// matching how the wire treats the raw key). `uuid()` is defined further down.
impl PartialOrd for OwnerKey {
    fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for OwnerKey {
    fn cmp(&self, other: &Self) -> core::cmp::Ordering {
        self.uuid().cmp(&other.uuid())
    }
}

impl std::fmt::Display for OwnerKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Agent(agent_key) => write!(f, "{agent_key}"),
            Self::Group(group_key) => write!(f, "{group_key}"),
        }
    }
}

/// error when the owner is a group while trying to convert an OwnerKey to an AgentKey
#[derive(Debug, Clone)]
pub struct OwnerIsGroupError(GroupKey);

impl std::fmt::Display for OwnerIsGroupError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "The owner is not an agent but the group {}", self.0)
    }
}

impl TryInto<AgentKey> for OwnerKey {
    type Error = OwnerIsGroupError;

    fn try_into(self) -> Result<AgentKey, Self::Error> {
        match self {
            Self::Agent(agent_key) => Ok(agent_key),
            Self::Group(group_key) => Err(OwnerIsGroupError(group_key)),
        }
    }
}

/// error when the owner is an agent while trying to convert an OwnerKey to a GroupKey
#[derive(Debug, Clone)]
pub struct OwnerIsAgentError(AgentKey);

impl std::fmt::Display for OwnerIsAgentError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "The owner is not a group but the agent {}", self.0)
    }
}

impl TryInto<GroupKey> for OwnerKey {
    type Error = OwnerIsAgentError;

    fn try_into(self) -> Result<GroupKey, Self::Error> {
        match self {
            Self::Agent(agent_key) => Err(OwnerIsAgentError(agent_key)),
            Self::Group(group_key) => Ok(group_key),
        }
    }
}

impl From<OwnerKey> for Key {
    fn from(val: OwnerKey) -> Self {
        match val {
            OwnerKey::Agent(agent_key) => agent_key.into(),
            OwnerKey::Group(group_key) => group_key.into(),
        }
    }
}

/// parse a viewer URI that is either an /about or /inspect URL for an agent group
/// or for a group and return the OwnerKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn app_agent_or_group_uri_as_owner_key_parser<'src>()
-> impl Parser<'src, &'src str, OwnerKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    app_agent_uri_as_agent_key_parser()
        .map(OwnerKey::Agent)
        .or(app_group_uri_as_group_key_parser().map(OwnerKey::Group))
}

impl Key {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0
    }
}

impl From<Uuid> for Key {
    fn from(value: Uuid) -> Self {
        Self(value)
    }
}

impl AgentKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for AgentKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

impl ClassifiedKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for ClassifiedKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

impl ExperienceKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for ExperienceKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

impl FriendKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for FriendKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

impl GroupKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for GroupKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

impl InventoryKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for InventoryKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

impl ObjectKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for ObjectKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

impl ParcelKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for ParcelKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

impl TextureKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for TextureKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

impl InventoryFolderKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for InventoryFolderKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

impl OwnerKey {
    /// The wrapped raw UUID, regardless of whether the owner is an agent or a
    /// group.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        match self {
            Self::Agent(agent_key) => agent_key.0.0,
            Self::Group(group_key) => group_key.0.0,
        }
    }
}

/// represents a Second Life key for a *role* within a group (e.g. the "Owners"
/// role, or the nil-keyed default "Everyone" role), as distinct from the
/// group's own [`GroupKey`]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct GroupRoleKey(pub Key);

impl std::fmt::Display for GroupRoleKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<GroupRoleKey> for Key {
    fn from(val: GroupRoleKey) -> Self {
        val.0
    }
}

impl GroupRoleKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for GroupRoleKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

/// parse a GroupRoleKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn group_role_key_parser<'src>()
-> impl Parser<'src, &'src str, GroupRoleKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>>
{
    key_parser().map(GroupRoleKey)
}

/// represents a Second Life key for a profile **pick** (the viewer's
/// `LLPickData::mPickID`) — a profile-listed place. The picks-side parallel of
/// [`ClassifiedKey`], kept distinct so the two cannot be transposed.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct PickKey(pub Key);

impl std::fmt::Display for PickKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<PickKey> for Key {
    fn from(val: PickKey) -> Self {
        val.0
    }
}

impl PickKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for PickKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

/// parse a PickKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn pick_key_parser<'src>()
-> impl Parser<'src, &'src str, PickKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    key_parser().map(PickKey)
}

/// represents a Second Life key for a group **notice** (the viewer's group-notice
/// `mNoticeID`) — one posting in a group's notice list.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct GroupNoticeKey(pub Key);

impl std::fmt::Display for GroupNoticeKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<GroupNoticeKey> for Key {
    fn from(val: GroupNoticeKey) -> Self {
        val.0
    }
}

impl GroupNoticeKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for GroupNoticeKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

/// parse a GroupNoticeKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn group_notice_key_parser<'src>()
-> impl Parser<'src, &'src str, GroupNoticeKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>>
{
    key_parser().map(GroupNoticeKey)
}

/// represents a Second Life key for a *mesh* asset — the UUID of a mesh asset,
/// as carried in the sculpt/mesh block of a prim whose shape comes from a mesh
/// rather than a sculpt texture. A mesh asset is emphatically not a
/// [`TextureKey`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub struct MeshKey(pub Key);

impl std::fmt::Display for MeshKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl From<MeshKey> for Key {
    fn from(val: MeshKey) -> Self {
        val.0
    }
}

impl MeshKey {
    /// The wrapped raw UUID.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        self.0.0
    }
}

impl From<Uuid> for MeshKey {
    fn from(value: Uuid) -> Self {
        Self(Key(value))
    }
}

/// parse a MeshKey
///
/// # Errors
///
/// returns an error if the string could not be parsed
#[cfg(feature = "chumsky")]
#[must_use]
pub fn mesh_key_parser<'src>()
-> impl Parser<'src, &'src str, MeshKey, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
    key_parser().map(MeshKey)
}

/// a key that is either an **agent** ([`AgentKey`]) or an in-world **object**
/// ([`ObjectKey`]), as selected by a separate source-type discriminator (an
/// avatar or a prim can be the source of chat, sounds, effects, …)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum::EnumIs)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub enum AgentOrObjectKey {
    /// the key is an agent
    Agent(AgentKey),
    /// the key is an in-world object
    Object(ObjectKey),
}

impl AgentOrObjectKey {
    /// The wrapped raw UUID, regardless of whether the key is an agent or an
    /// object.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        match self {
            Self::Agent(agent_key) => agent_key.0.0,
            Self::Object(object_key) => object_key.0.0,
        }
    }
}

// Order by the underlying UUID, not by variant, so agents and objects share one
// key space.
impl PartialOrd for AgentOrObjectKey {
    fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for AgentOrObjectKey {
    fn cmp(&self, other: &Self) -> core::cmp::Ordering {
        self.uuid().cmp(&other.uuid())
    }
}

impl std::fmt::Display for AgentOrObjectKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Agent(agent_key) => write!(f, "{agent_key}"),
            Self::Object(object_key) => write!(f, "{object_key}"),
        }
    }
}

impl From<AgentOrObjectKey> for Key {
    fn from(val: AgentOrObjectKey) -> Self {
        match val {
            AgentOrObjectKey::Agent(agent_key) => agent_key.into(),
            AgentOrObjectKey::Object(object_key) => object_key.into(),
        }
    }
}

/// a key that is either an inventory **item** ([`InventoryKey`]) or a whole
/// inventory **folder/category** ([`InventoryFolderKey`]), as selected by a
/// separate asset-type discriminator
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum::EnumIs)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub enum InventoryItemOrFolderKey {
    /// the key refers to a single inventory item
    Item(InventoryKey),
    /// the key refers to a whole inventory folder/category
    Folder(InventoryFolderKey),
}

impl InventoryItemOrFolderKey {
    /// The wrapped raw UUID, regardless of whether it refers to an item or a
    /// folder.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        match self {
            Self::Item(item_key) => item_key.0.0,
            Self::Folder(folder_key) => folder_key.0.0,
        }
    }
}

// Order by the underlying UUID, not by variant, so items and folders share one
// key space.
impl PartialOrd for InventoryItemOrFolderKey {
    fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for InventoryItemOrFolderKey {
    fn cmp(&self, other: &Self) -> core::cmp::Ordering {
        self.uuid().cmp(&other.uuid())
    }
}

impl std::fmt::Display for InventoryItemOrFolderKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Item(item_key) => write!(f, "{item_key}"),
            Self::Folder(folder_key) => write!(f, "{folder_key}"),
        }
    }
}

impl From<InventoryItemOrFolderKey> for Key {
    fn from(val: InventoryItemOrFolderKey) -> Self {
        match val {
            InventoryItemOrFolderKey::Item(item_key) => item_key.into(),
            InventoryItemOrFolderKey::Folder(folder_key) => folder_key.into(),
        }
    }
}

/// the asset backing a prim's sculpt/mesh shape: either a sculpt **texture**
/// ([`TextureKey`]) or a **mesh** asset ([`MeshKey`]), as selected by the prim's
/// sculpt-type discriminator
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum::EnumIs)]
#[expect(
    clippy::module_name_repetitions,
    reason = "the type is going to be used outside this module"
)]
pub enum SculptOrMeshKey {
    /// the prim is a sculpty: the key is a sculpt texture
    Sculpt(TextureKey),
    /// the prim is a mesh: the key is a mesh asset
    Mesh(MeshKey),
}

impl SculptOrMeshKey {
    /// The wrapped raw UUID, regardless of whether it is a sculpt texture or a
    /// mesh asset.
    #[must_use]
    pub const fn uuid(&self) -> Uuid {
        match self {
            Self::Sculpt(texture_key) => texture_key.0.0,
            Self::Mesh(mesh_key) => mesh_key.0.0,
        }
    }
}

// Order by the underlying UUID, not by variant, so sculpt textures and mesh
// assets share one key space.
impl PartialOrd for SculptOrMeshKey {
    fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for SculptOrMeshKey {
    fn cmp(&self, other: &Self) -> core::cmp::Ordering {
        self.uuid().cmp(&other.uuid())
    }
}

impl std::fmt::Display for SculptOrMeshKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Sculpt(texture_key) => write!(f, "{texture_key}"),
            Self::Mesh(mesh_key) => write!(f, "{mesh_key}"),
        }
    }
}

impl From<SculptOrMeshKey> for Key {
    fn from(val: SculptOrMeshKey) -> Self {
        match val {
            SculptOrMeshKey::Sculpt(texture_key) => texture_key.into(),
            SculptOrMeshKey::Mesh(mesh_key) => mesh_key.into(),
        }
    }
}