+309
-11
Cargo.lock
+309
-11
Cargo.lock
···
3
version = 4
4
5
[[package]]
6
name = "aho-corasick"
7
version = "1.1.3"
8
source = "registry+https://github.com/rust-lang/crates.io-index"
···
83
checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270"
84
85
[[package]]
86
name = "borsh"
87
version = "1.5.7"
88
source = "registry+https://github.com/rust-lang/crates.io-index"
···
92
]
93
94
[[package]]
95
name = "bumpalo"
96
version = "3.19.0"
97
source = "registry+https://github.com/rust-lang/crates.io-index"
···
108
]
109
110
[[package]]
111
name = "cfg-if"
112
version = "1.0.3"
113
source = "registry+https://github.com/rust-lang/crates.io-index"
···
133
]
134
135
[[package]]
136
name = "cid"
137
version = "0.11.1"
138
source = "registry+https://github.com/rust-lang/crates.io-index"
···
177
"heck",
178
"proc-macro2",
179
"quote",
180
-
"syn",
181
]
182
183
[[package]]
···
208
]
209
210
[[package]]
211
name = "data-encoding"
212
version = "2.9.0"
213
source = "registry+https://github.com/rust-lang/crates.io-index"
···
230
checksum = "8d162beedaa69905488a8da94f5ac3edb4dd4788b732fadb7bd120b2625c1976"
231
dependencies = [
232
"data-encoding",
233
-
"syn",
234
]
235
236
[[package]]
···
255
]
256
257
[[package]]
258
name = "hashbrown"
259
version = "0.16.0"
260
source = "registry+https://github.com/rust-lang/crates.io-index"
···
267
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
268
269
[[package]]
270
name = "iana-time-zone"
271
version = "0.1.64"
272
source = "registry+https://github.com/rust-lang/crates.io-index"
···
301
]
302
303
[[package]]
304
name = "is_terminal_polyfill"
305
version = "1.70.1"
306
source = "registry+https://github.com/rust-lang/crates.io-index"
···
326
dependencies = [
327
"chrono",
328
"cid",
329
"miette",
330
"multibase",
331
"multihash",
···
334
"serde_html_form",
335
"serde_json",
336
"smol_str",
337
-
"thiserror",
338
]
339
340
[[package]]
···
345
dependencies = [
346
"once_cell",
347
"wasm-bindgen",
348
]
349
350
[[package]]
···
384
dependencies = [
385
"proc-macro2",
386
"quote",
387
-
"syn",
388
]
389
390
[[package]]
391
name = "multibase"
392
version = "0.9.1"
393
source = "registry+https://github.com/rust-lang/crates.io-index"
···
410
]
411
412
[[package]]
413
name = "num-traits"
414
version = "0.2.19"
415
source = "registry+https://github.com/rust-lang/crates.io-index"
···
437
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
438
439
[[package]]
440
name = "proc-macro2"
441
version = "1.0.101"
442
source = "registry+https://github.com/rust-lang/crates.io-index"
···
455
]
456
457
[[package]]
458
name = "regex"
459
version = "1.11.3"
460
source = "registry+https://github.com/rust-lang/crates.io-index"
···
531
dependencies = [
532
"proc-macro2",
533
"quote",
534
-
"syn",
535
]
536
537
[[package]]
···
561
]
562
563
[[package]]
564
name = "shlex"
565
version = "1.3.0"
566
source = "registry+https://github.com/rust-lang/crates.io-index"
567
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
568
569
[[package]]
570
name = "smol_str"
571
version = "0.3.2"
572
source = "registry+https://github.com/rust-lang/crates.io-index"
···
577
]
578
579
[[package]]
580
name = "strsim"
581
version = "0.11.1"
582
source = "registry+https://github.com/rust-lang/crates.io-index"
···
584
585
[[package]]
586
name = "syn"
587
version = "2.0.106"
588
source = "registry+https://github.com/rust-lang/crates.io-index"
589
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
···
595
596
[[package]]
597
name = "thiserror"
598
version = "2.0.16"
599
source = "registry+https://github.com/rust-lang/crates.io-index"
600
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
601
dependencies = [
602
-
"thiserror-impl",
603
]
604
605
[[package]]
···
610
dependencies = [
611
"proc-macro2",
612
"quote",
613
-
"syn",
614
]
615
616
[[package]]
617
name = "unicode-ident"
618
version = "1.0.19"
619
source = "registry+https://github.com/rust-lang/crates.io-index"
···
638
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
639
640
[[package]]
641
name = "wasm-bindgen"
642
version = "0.2.104"
643
source = "registry+https://github.com/rust-lang/crates.io-index"
···
660
"log",
661
"proc-macro2",
662
"quote",
663
-
"syn",
664
"wasm-bindgen-shared",
665
]
666
···
682
dependencies = [
683
"proc-macro2",
684
"quote",
685
-
"syn",
686
"wasm-bindgen-backend",
687
"wasm-bindgen-shared",
688
]
···
717
dependencies = [
718
"proc-macro2",
719
"quote",
720
-
"syn",
721
]
722
723
[[package]]
···
728
dependencies = [
729
"proc-macro2",
730
"quote",
731
-
"syn",
732
]
733
734
[[package]]
···
3
version = 4
4
5
[[package]]
6
+
name = "abnf"
7
+
version = "0.13.0"
8
+
source = "registry+https://github.com/rust-lang/crates.io-index"
9
+
checksum = "087113bd50d9adce24850eed5d0476c7d199d532fce8fab5173650331e09033a"
10
+
dependencies = [
11
+
"abnf-core",
12
+
"nom",
13
+
]
14
+
15
+
[[package]]
16
+
name = "abnf-core"
17
+
version = "0.5.0"
18
+
source = "registry+https://github.com/rust-lang/crates.io-index"
19
+
checksum = "c44e09c43ae1c368fb91a03a566472d0087c26cf7e1b9e8e289c14ede681dd7d"
20
+
dependencies = [
21
+
"nom",
22
+
]
23
+
24
+
[[package]]
25
name = "aho-corasick"
26
version = "1.1.3"
27
source = "registry+https://github.com/rust-lang/crates.io-index"
···
102
checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270"
103
104
[[package]]
105
+
name = "block-buffer"
106
+
version = "0.10.4"
107
+
source = "registry+https://github.com/rust-lang/crates.io-index"
108
+
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
109
+
dependencies = [
110
+
"generic-array",
111
+
]
112
+
113
+
[[package]]
114
name = "borsh"
115
version = "1.5.7"
116
source = "registry+https://github.com/rust-lang/crates.io-index"
···
120
]
121
122
[[package]]
123
+
name = "btree-range-map"
124
+
version = "0.7.2"
125
+
source = "registry+https://github.com/rust-lang/crates.io-index"
126
+
checksum = "1be5c9672446d3800bcbcaabaeba121fe22f1fb25700c4562b22faf76d377c33"
127
+
dependencies = [
128
+
"btree-slab",
129
+
"cc-traits",
130
+
"range-traits",
131
+
"serde",
132
+
"slab",
133
+
]
134
+
135
+
[[package]]
136
+
name = "btree-slab"
137
+
version = "0.6.1"
138
+
source = "registry+https://github.com/rust-lang/crates.io-index"
139
+
checksum = "7a2b56d3029f075c4fa892428a098425b86cef5c89ae54073137ece416aef13c"
140
+
dependencies = [
141
+
"cc-traits",
142
+
"slab",
143
+
"smallvec",
144
+
]
145
+
146
+
[[package]]
147
name = "bumpalo"
148
version = "3.19.0"
149
source = "registry+https://github.com/rust-lang/crates.io-index"
···
160
]
161
162
[[package]]
163
+
name = "cc-traits"
164
+
version = "2.0.0"
165
+
source = "registry+https://github.com/rust-lang/crates.io-index"
166
+
checksum = "060303ef31ef4a522737e1b1ab68c67916f2a787bb2f4f54f383279adba962b5"
167
+
dependencies = [
168
+
"slab",
169
+
]
170
+
171
+
[[package]]
172
name = "cfg-if"
173
version = "1.0.3"
174
source = "registry+https://github.com/rust-lang/crates.io-index"
···
194
]
195
196
[[package]]
197
+
name = "ciborium"
198
+
version = "0.2.2"
199
+
source = "registry+https://github.com/rust-lang/crates.io-index"
200
+
checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e"
201
+
dependencies = [
202
+
"ciborium-io",
203
+
"ciborium-ll",
204
+
"serde",
205
+
]
206
+
207
+
[[package]]
208
+
name = "ciborium-io"
209
+
version = "0.2.2"
210
+
source = "registry+https://github.com/rust-lang/crates.io-index"
211
+
checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757"
212
+
213
+
[[package]]
214
+
name = "ciborium-ll"
215
+
version = "0.2.2"
216
+
source = "registry+https://github.com/rust-lang/crates.io-index"
217
+
checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9"
218
+
dependencies = [
219
+
"ciborium-io",
220
+
"half",
221
+
]
222
+
223
+
[[package]]
224
name = "cid"
225
version = "0.11.1"
226
source = "registry+https://github.com/rust-lang/crates.io-index"
···
265
"heck",
266
"proc-macro2",
267
"quote",
268
+
"syn 2.0.106",
269
]
270
271
[[package]]
···
296
]
297
298
[[package]]
299
+
name = "cpufeatures"
300
+
version = "0.2.17"
301
+
source = "registry+https://github.com/rust-lang/crates.io-index"
302
+
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
303
+
dependencies = [
304
+
"libc",
305
+
]
306
+
307
+
[[package]]
308
+
name = "crunchy"
309
+
version = "0.2.4"
310
+
source = "registry+https://github.com/rust-lang/crates.io-index"
311
+
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
312
+
313
+
[[package]]
314
+
name = "crypto-common"
315
+
version = "0.1.6"
316
+
source = "registry+https://github.com/rust-lang/crates.io-index"
317
+
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
318
+
dependencies = [
319
+
"generic-array",
320
+
"typenum",
321
+
]
322
+
323
+
[[package]]
324
name = "data-encoding"
325
version = "2.9.0"
326
source = "registry+https://github.com/rust-lang/crates.io-index"
···
343
checksum = "8d162beedaa69905488a8da94f5ac3edb4dd4788b732fadb7bd120b2625c1976"
344
dependencies = [
345
"data-encoding",
346
+
"syn 2.0.106",
347
+
]
348
+
349
+
[[package]]
350
+
name = "digest"
351
+
version = "0.10.7"
352
+
source = "registry+https://github.com/rust-lang/crates.io-index"
353
+
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
354
+
dependencies = [
355
+
"block-buffer",
356
+
"crypto-common",
357
]
358
359
[[package]]
···
378
]
379
380
[[package]]
381
+
name = "generic-array"
382
+
version = "0.14.7"
383
+
source = "registry+https://github.com/rust-lang/crates.io-index"
384
+
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
385
+
dependencies = [
386
+
"typenum",
387
+
"version_check",
388
+
]
389
+
390
+
[[package]]
391
+
name = "half"
392
+
version = "2.6.0"
393
+
source = "registry+https://github.com/rust-lang/crates.io-index"
394
+
checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9"
395
+
dependencies = [
396
+
"cfg-if",
397
+
"crunchy",
398
+
]
399
+
400
+
[[package]]
401
name = "hashbrown"
402
version = "0.16.0"
403
source = "registry+https://github.com/rust-lang/crates.io-index"
···
410
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
411
412
[[package]]
413
+
name = "hex_fmt"
414
+
version = "0.3.0"
415
+
source = "registry+https://github.com/rust-lang/crates.io-index"
416
+
checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f"
417
+
418
+
[[package]]
419
name = "iana-time-zone"
420
version = "0.1.64"
421
source = "registry+https://github.com/rust-lang/crates.io-index"
···
450
]
451
452
[[package]]
453
+
name = "indoc"
454
+
version = "2.0.6"
455
+
source = "registry+https://github.com/rust-lang/crates.io-index"
456
+
checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
457
+
458
+
[[package]]
459
name = "is_terminal_polyfill"
460
version = "1.70.1"
461
source = "registry+https://github.com/rust-lang/crates.io-index"
···
481
dependencies = [
482
"chrono",
483
"cid",
484
+
"langtag",
485
"miette",
486
"multibase",
487
"multihash",
···
490
"serde_html_form",
491
"serde_json",
492
"smol_str",
493
+
"thiserror 2.0.16",
494
]
495
496
[[package]]
···
501
dependencies = [
502
"once_cell",
503
"wasm-bindgen",
504
+
]
505
+
506
+
[[package]]
507
+
name = "langtag"
508
+
version = "0.4.0"
509
+
source = "registry+https://github.com/rust-lang/crates.io-index"
510
+
checksum = "9ecb4c689a30e48ebeaa14237f34037e300dd072e6ad21a9ec72e810ff3c6600"
511
+
dependencies = [
512
+
"serde",
513
+
"static-regular-grammar",
514
+
"thiserror 1.0.69",
515
]
516
517
[[package]]
···
551
dependencies = [
552
"proc-macro2",
553
"quote",
554
+
"syn 2.0.106",
555
]
556
557
[[package]]
558
+
name = "minimal-lexical"
559
+
version = "0.2.1"
560
+
source = "registry+https://github.com/rust-lang/crates.io-index"
561
+
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
562
+
563
+
[[package]]
564
name = "multibase"
565
version = "0.9.1"
566
source = "registry+https://github.com/rust-lang/crates.io-index"
···
583
]
584
585
[[package]]
586
+
name = "nom"
587
+
version = "7.1.3"
588
+
source = "registry+https://github.com/rust-lang/crates.io-index"
589
+
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
590
+
dependencies = [
591
+
"memchr",
592
+
"minimal-lexical",
593
+
]
594
+
595
+
[[package]]
596
name = "num-traits"
597
version = "0.2.19"
598
source = "registry+https://github.com/rust-lang/crates.io-index"
···
620
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
621
622
[[package]]
623
+
name = "proc-macro-error"
624
+
version = "1.0.4"
625
+
source = "registry+https://github.com/rust-lang/crates.io-index"
626
+
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
627
+
dependencies = [
628
+
"proc-macro-error-attr",
629
+
"proc-macro2",
630
+
"quote",
631
+
"syn 1.0.109",
632
+
"version_check",
633
+
]
634
+
635
+
[[package]]
636
+
name = "proc-macro-error-attr"
637
+
version = "1.0.4"
638
+
source = "registry+https://github.com/rust-lang/crates.io-index"
639
+
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
640
+
dependencies = [
641
+
"proc-macro2",
642
+
"quote",
643
+
"version_check",
644
+
]
645
+
646
+
[[package]]
647
name = "proc-macro2"
648
version = "1.0.101"
649
source = "registry+https://github.com/rust-lang/crates.io-index"
···
662
]
663
664
[[package]]
665
+
name = "range-traits"
666
+
version = "0.3.2"
667
+
source = "registry+https://github.com/rust-lang/crates.io-index"
668
+
checksum = "d20581732dd76fa913c7dff1a2412b714afe3573e94d41c34719de73337cc8ab"
669
+
670
+
[[package]]
671
name = "regex"
672
version = "1.11.3"
673
source = "registry+https://github.com/rust-lang/crates.io-index"
···
744
dependencies = [
745
"proc-macro2",
746
"quote",
747
+
"syn 2.0.106",
748
]
749
750
[[package]]
···
774
]
775
776
[[package]]
777
+
name = "sha2"
778
+
version = "0.10.9"
779
+
source = "registry+https://github.com/rust-lang/crates.io-index"
780
+
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
781
+
dependencies = [
782
+
"cfg-if",
783
+
"cpufeatures",
784
+
"digest",
785
+
]
786
+
787
+
[[package]]
788
name = "shlex"
789
version = "1.3.0"
790
source = "registry+https://github.com/rust-lang/crates.io-index"
791
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
792
793
[[package]]
794
+
name = "slab"
795
+
version = "0.4.11"
796
+
source = "registry+https://github.com/rust-lang/crates.io-index"
797
+
checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589"
798
+
799
+
[[package]]
800
+
name = "smallvec"
801
+
version = "1.15.1"
802
+
source = "registry+https://github.com/rust-lang/crates.io-index"
803
+
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
804
+
805
+
[[package]]
806
name = "smol_str"
807
version = "0.3.2"
808
source = "registry+https://github.com/rust-lang/crates.io-index"
···
813
]
814
815
[[package]]
816
+
name = "static-regular-grammar"
817
+
version = "2.0.2"
818
+
source = "registry+https://github.com/rust-lang/crates.io-index"
819
+
checksum = "4f4a6c40247579acfbb138c3cd7de3dab113ab4ac6227f1b7de7d626ee667957"
820
+
dependencies = [
821
+
"abnf",
822
+
"btree-range-map",
823
+
"ciborium",
824
+
"hex_fmt",
825
+
"indoc",
826
+
"proc-macro-error",
827
+
"proc-macro2",
828
+
"quote",
829
+
"serde",
830
+
"sha2",
831
+
"syn 2.0.106",
832
+
"thiserror 1.0.69",
833
+
]
834
+
835
+
[[package]]
836
name = "strsim"
837
version = "0.11.1"
838
source = "registry+https://github.com/rust-lang/crates.io-index"
···
840
841
[[package]]
842
name = "syn"
843
+
version = "1.0.109"
844
+
source = "registry+https://github.com/rust-lang/crates.io-index"
845
+
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
846
+
dependencies = [
847
+
"proc-macro2",
848
+
"unicode-ident",
849
+
]
850
+
851
+
[[package]]
852
+
name = "syn"
853
version = "2.0.106"
854
source = "registry+https://github.com/rust-lang/crates.io-index"
855
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
···
861
862
[[package]]
863
name = "thiserror"
864
+
version = "1.0.69"
865
+
source = "registry+https://github.com/rust-lang/crates.io-index"
866
+
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
867
+
dependencies = [
868
+
"thiserror-impl 1.0.69",
869
+
]
870
+
871
+
[[package]]
872
+
name = "thiserror"
873
version = "2.0.16"
874
source = "registry+https://github.com/rust-lang/crates.io-index"
875
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
876
dependencies = [
877
+
"thiserror-impl 2.0.16",
878
+
]
879
+
880
+
[[package]]
881
+
name = "thiserror-impl"
882
+
version = "1.0.69"
883
+
source = "registry+https://github.com/rust-lang/crates.io-index"
884
+
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
885
+
dependencies = [
886
+
"proc-macro2",
887
+
"quote",
888
+
"syn 2.0.106",
889
]
890
891
[[package]]
···
896
dependencies = [
897
"proc-macro2",
898
"quote",
899
+
"syn 2.0.106",
900
]
901
902
[[package]]
903
+
name = "typenum"
904
+
version = "1.18.0"
905
+
source = "registry+https://github.com/rust-lang/crates.io-index"
906
+
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
907
+
908
+
[[package]]
909
name = "unicode-ident"
910
version = "1.0.19"
911
source = "registry+https://github.com/rust-lang/crates.io-index"
···
930
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
931
932
[[package]]
933
+
name = "version_check"
934
+
version = "0.9.5"
935
+
source = "registry+https://github.com/rust-lang/crates.io-index"
936
+
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
937
+
938
+
[[package]]
939
name = "wasm-bindgen"
940
version = "0.2.104"
941
source = "registry+https://github.com/rust-lang/crates.io-index"
···
958
"log",
959
"proc-macro2",
960
"quote",
961
+
"syn 2.0.106",
962
"wasm-bindgen-shared",
963
]
964
···
980
dependencies = [
981
"proc-macro2",
982
"quote",
983
+
"syn 2.0.106",
984
"wasm-bindgen-backend",
985
"wasm-bindgen-shared",
986
]
···
1015
dependencies = [
1016
"proc-macro2",
1017
"quote",
1018
+
"syn 2.0.106",
1019
]
1020
1021
[[package]]
···
1026
dependencies = [
1027
"proc-macro2",
1028
"quote",
1029
+
"syn 2.0.106",
1030
]
1031
1032
[[package]]
+1
crates/jacquard-common/Cargo.toml
+1
crates/jacquard-common/Cargo.toml
+1
crates/jacquard-common/src/types.rs
+1
crates/jacquard-common/src/types.rs
+112
crates/jacquard-common/src/types/language.rs
+112
crates/jacquard-common/src/types/language.rs
···
···
1
+
use serde::{Deserialize, Deserializer, Serialize, de::Error};
2
+
use smol_str::{SmolStr, ToSmolStr};
3
+
use std::fmt;
4
+
use std::{ops::Deref, str::FromStr};
5
+
6
+
use crate::CowStr;
7
+
8
+
/// A [Timestamp Identifier].
9
+
///
10
+
/// [Timestamp Identifier]: https://atproto.com/specs/lang
11
+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Hash)]
12
+
#[serde(transparent)]
13
+
#[repr(transparent)]
14
+
pub struct Lang(SmolStr);
15
+
16
+
impl Lang {
17
+
/// Parses an IETF language tag from the given string.
18
+
pub fn new<T>(lang: &T) -> Result<Self, langtag::InvalidLangTag<&T>>
19
+
where
20
+
T: AsRef<str> + ?Sized,
21
+
{
22
+
let tag = langtag::LangTag::new(lang)?;
23
+
Ok(Lang(SmolStr::new_inline(tag.as_str())))
24
+
}
25
+
26
+
/// Infallible constructor for when you *know* the string is a valid IETF language tag.
27
+
/// Will panic on invalid tag. If you're manually decoding atproto records
28
+
/// or API values you know are valid (rather than using serde), this is the one to use.
29
+
/// The From<String> and From<CowStr> impls use the same logic.
30
+
pub fn raw(lang: impl AsRef<str>) -> Self {
31
+
let lang = lang.as_ref();
32
+
let tag = langtag::LangTag::new(lang).expect("valid IETF language tag");
33
+
Lang(SmolStr::new_inline(tag.as_str()))
34
+
}
35
+
36
+
/// Infallible constructor for when you *know* the string is a valid IETF language tag.
37
+
/// Marked unsafe because responsibility for upholding the invariant is on the developer.
38
+
pub unsafe fn unchecked(lang: impl AsRef<str>) -> Self {
39
+
let lang = lang.as_ref();
40
+
Self(SmolStr::new_inline(lang))
41
+
}
42
+
43
+
/// Returns the LANG as a string slice.
44
+
pub fn as_str(&self) -> &str {
45
+
{
46
+
let this = &self.0;
47
+
this
48
+
}
49
+
}
50
+
}
51
+
52
+
impl FromStr for Lang {
53
+
type Err = SmolStr;
54
+
55
+
fn from_str(s: &str) -> Result<Self, Self::Err> {
56
+
Self::new(s).map_err(|e| e.0.to_smolstr())
57
+
}
58
+
}
59
+
60
+
impl<'de> Deserialize<'de> for Lang {
61
+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
62
+
where
63
+
D: Deserializer<'de>,
64
+
{
65
+
let value: &str = Deserialize::deserialize(deserializer)?;
66
+
Self::new(value).map_err(D::Error::custom)
67
+
}
68
+
}
69
+
70
+
impl fmt::Display for Lang {
71
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72
+
f.write_str(&self.0)
73
+
}
74
+
}
75
+
76
+
impl From<Lang> for String {
77
+
fn from(value: Lang) -> Self {
78
+
value.0.to_string()
79
+
}
80
+
}
81
+
82
+
impl From<Lang> for SmolStr {
83
+
fn from(value: Lang) -> Self {
84
+
value.0
85
+
}
86
+
}
87
+
88
+
impl From<String> for Lang {
89
+
fn from(value: String) -> Self {
90
+
Self::raw(&value)
91
+
}
92
+
}
93
+
94
+
impl<'t> From<CowStr<'t>> for Lang {
95
+
fn from(value: CowStr<'t>) -> Self {
96
+
Self::raw(&value)
97
+
}
98
+
}
99
+
100
+
impl AsRef<str> for Lang {
101
+
fn as_ref(&self) -> &str {
102
+
self.as_str()
103
+
}
104
+
}
105
+
106
+
impl Deref for Lang {
107
+
type Target = str;
108
+
109
+
fn deref(&self) -> &Self::Target {
110
+
self.as_str()
111
+
}
112
+
}