    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
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189

    use std::collections::BTreeMap;
    use std::fmt::{self, Display, Write};
    use std::path::PathBuf;
    use std::str;

    use serde::de::{self, IntoDeserializer as _, Unexpected};
    use serde::ser;
    use serde::{Deserialize, Serialize};
    use serde_untagged::UntaggedEnumVisitor;

    use crate::core::PackageIdSpec;
    use crate::util::RustVersion;

    /// This type is used to deserialize `Cargo.toml` files.
    #[derive(Debug, Deserialize, Serialize)]
    #[serde(rename_all = "kebab-case")]
    pub struct TomlManifest {
        pub cargo_features: Option<Vec<String>>,
        pub package: Option<Box<TomlPackage>>,
        pub project: Option<Box<TomlPackage>>,
        pub profile: Option<TomlProfiles>,
        pub lib: Option<TomlLibTarget>,
        pub bin: Option<Vec<TomlBinTarget>>,
        pub example: Option<Vec<TomlExampleTarget>>,
        pub test: Option<Vec<TomlTestTarget>>,
        pub bench: Option<Vec<TomlTestTarget>>,
        pub dependencies: Option<BTreeMap<String, MaybeWorkspaceDependency>>,
        pub dev_dependencies: Option<BTreeMap<String, MaybeWorkspaceDependency>>,
        #[serde(rename = "dev_dependencies")]
        pub dev_dependencies2: Option<BTreeMap<String, MaybeWorkspaceDependency>>,
        pub build_dependencies: Option<BTreeMap<String, MaybeWorkspaceDependency>>,
        #[serde(rename = "build_dependencies")]
        pub build_dependencies2: Option<BTreeMap<String, MaybeWorkspaceDependency>>,
        pub features: Option<BTreeMap<String, Vec<String>>>,
        pub target: Option<BTreeMap<String, TomlPlatform>>,
        pub replace: Option<BTreeMap<String, TomlDependency>>,
        pub patch: Option<BTreeMap<String, BTreeMap<String, TomlDependency>>>,
        pub workspace: Option<TomlWorkspace>,
        pub badges: Option<MaybeWorkspaceBtreeMap>,
        pub lints: Option<MaybeWorkspaceLints>,
    }

    impl TomlManifest {
        pub fn has_profiles(&self) -> bool {
            self.profile.is_some()
        }

        pub fn dev_dependencies(&self) -> Option<&BTreeMap<String, MaybeWorkspaceDependency>> {
            self.dev_dependencies
                .as_ref()
                .or(self.dev_dependencies2.as_ref())
        }

        pub fn build_dependencies(&self) -> Option<&BTreeMap<String, MaybeWorkspaceDependency>> {
            self.build_dependencies
                .as_ref()
                .or(self.build_dependencies2.as_ref())
        }

        pub fn features(&self) -> Option<&BTreeMap<String, Vec<String>>> {
            self.features.as_ref()
        }
    }

    #[derive(Debug, Deserialize, Serialize, Clone)]
    #[serde(rename_all = "kebab-case")]
    pub struct TomlWorkspace {
        pub members: Option<Vec<String>>,
        pub exclude: Option<Vec<String>>,
        pub default_members: Option<Vec<String>>,
        pub resolver: Option<String>,
        pub metadata: Option<toml::Value>,

        // Properties that can be inherited by members.
        pub package: Option<InheritableFields>,
        pub dependencies: Option<BTreeMap<String, TomlDependency>>,
        pub lints: Option<TomlLints>,
    }

    /// A group of fields that are inheritable by members of the workspace
    #[derive(Clone, Debug, Default, Deserialize, Serialize)]
    #[serde(rename_all = "kebab-case")]
    pub struct InheritableFields {
        // We use skip here since it will never be present when deserializing
        // and we don't want it present when serializing
        #[serde(skip)]
        pub dependencies: Option<BTreeMap<String, TomlDependency>>,
        #[serde(skip)]
        pub lints: Option<TomlLints>,

        pub version: Option<semver::Version>,
        pub authors: Option<Vec<String>>,
        pub description: Option<String>,
        pub homepage: Option<String>,
        pub documentation: Option<String>,
        pub readme: Option<StringOrBool>,
        pub keywords: Option<Vec<String>>,
        pub categories: Option<Vec<String>>,
        pub license: Option<String>,
        pub license_file: Option<String>,
        pub repository: Option<String>,
        pub publish: Option<VecStringOrBool>,
        pub edition: Option<String>,
        pub badges: Option<BTreeMap<String, BTreeMap<String, String>>>,
        pub exclude: Option<Vec<String>>,
        pub include: Option<Vec<String>>,
        pub rust_version: Option<RustVersion>,
        // We use skip here since it will never be present when deserializing
        // and we don't want it present when serializing
        #[serde(skip)]
        pub ws_root: PathBuf,
    }

    /// Represents the `package`/`project` sections of a `Cargo.toml`.
    ///
    /// Note that the order of the fields matters, since this is the order they
    /// are serialized to a TOML file. For example, you cannot have values after
    /// the field `metadata`, since it is a table and values cannot appear after
    /// tables.
    #[derive(Deserialize, Serialize, Clone, Debug)]
    #[serde(rename_all = "kebab-case")]
    pub struct TomlPackage {
        pub edition: Option<MaybeWorkspaceString>,
        pub rust_version: Option<MaybeWorkspaceRustVersion>,
        pub name: String,
        pub version: Option<MaybeWorkspaceSemverVersion>,
        pub authors: Option<MaybeWorkspaceVecString>,
        pub build: Option<StringOrBool>,
        pub metabuild: Option<StringOrVec>,
        pub default_target: Option<String>,
        pub forced_target: Option<String>,
        pub links: Option<String>,
        pub exclude: Option<MaybeWorkspaceVecString>,
        pub include: Option<MaybeWorkspaceVecString>,
        pub publish: Option<MaybeWorkspaceVecStringOrBool>,
        pub workspace: Option<String>,
        pub im_a_teapot: Option<bool>,
        pub autobins: Option<bool>,
        pub autoexamples: Option<bool>,
        pub autotests: Option<bool>,
        pub autobenches: Option<bool>,
        pub default_run: Option<String>,

        // Package metadata.
        pub description: Option<MaybeWorkspaceString>,
        pub homepage: Option<MaybeWorkspaceString>,
        pub documentation: Option<MaybeWorkspaceString>,
        pub readme: Option<MaybeWorkspaceStringOrBool>,
        pub keywords: Option<MaybeWorkspaceVecString>,
        pub categories: Option<MaybeWorkspaceVecString>,
        pub license: Option<MaybeWorkspaceString>,
        pub license_file: Option<MaybeWorkspaceString>,
        pub repository: Option<MaybeWorkspaceString>,
        pub resolver: Option<String>,

        pub metadata: Option<toml::Value>,

        /// Provide a helpful error message for a common user error.
        #[serde(rename = "cargo-features", skip_serializing)]
        pub _invalid_cargo_features: Option<InvalidCargoFeatures>,
    }

    /// An enum that allows for inheriting keys from a workspace in a Cargo.toml.
    #[derive(Serialize, Copy, Clone, Debug)]
    #[serde(untagged)]
    pub enum MaybeWorkspace<T, W> {
        /// The "defined" type, or the type that that is used when not inheriting from a workspace.
        Defined(T),
        /// The type when inheriting from a workspace.
        Workspace(W),
    }

    //. This already has a `Deserialize` impl from version_trim_whitespace
    pub type MaybeWorkspaceSemverVersion = MaybeWorkspace<semver::Version, TomlWorkspaceField>;
    impl<'de> de::Deserialize<'de> for MaybeWorkspaceSemverVersion {
        fn deserialize<D>(d: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            UntaggedEnumVisitor::new()
                .expecting("SemVer version")
                .string(
                    |value| match value.trim().parse().map_err(de::Error::custom) {
                        Ok(parsed) => Ok(MaybeWorkspace::Defined(parsed)),
                        Err(e) => Err(e),
                    },
                )
                .map(|value| value.deserialize().map(MaybeWorkspace::Workspace))
                .deserialize(d)
        }
    }

    pub type MaybeWorkspaceString = MaybeWorkspace<String, TomlWorkspaceField>;
    impl<'de> de::Deserialize<'de> for MaybeWorkspaceString {
        fn deserialize<D>(d: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            struct Visitor;

            impl<'de> de::Visitor<'de> for Visitor {
                type Value = MaybeWorkspaceString;

                fn expecting(&self, f: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
                    f.write_str("a string or workspace")
                }

                fn visit_string<E>(self, value: String) -> Result<Self::Value, E>
                where
                    E: de::Error,
                {
                    Ok(MaybeWorkspaceString::Defined(value))
                }

                fn visit_map<V>(self, map: V) -> Result<Self::Value, V::Error>
                where
                    V: de::MapAccess<'de>,
                {
                    let mvd = de::value::MapAccessDeserializer::new(map);
                    TomlWorkspaceField::deserialize(mvd).map(MaybeWorkspace::Workspace)
                }
            }

            d.deserialize_any(Visitor)
        }
    }

    pub type MaybeWorkspaceRustVersion = MaybeWorkspace<RustVersion, TomlWorkspaceField>;
    impl<'de> de::Deserialize<'de> for MaybeWorkspaceRustVersion {
        fn deserialize<D>(d: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            struct Visitor;

            impl<'de> de::Visitor<'de> for Visitor {
                type Value = MaybeWorkspaceRustVersion;

                fn expecting(&self, f: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
                    f.write_str("a semver or workspace")
                }

                fn visit_string<E>(self, value: String) -> Result<Self::Value, E>
                where
                    E: de::Error,
                {
                    let value = value.parse::<RustVersion>().map_err(|e| E::custom(e))?;
                    Ok(MaybeWorkspaceRustVersion::Defined(value))
                }

                fn visit_map<V>(self, map: V) -> Result<Self::Value, V::Error>
                where
                    V: de::MapAccess<'de>,
                {
                    let mvd = de::value::MapAccessDeserializer::new(map);
                    TomlWorkspaceField::deserialize(mvd).map(MaybeWorkspace::Workspace)
                }
            }

            d.deserialize_any(Visitor)
        }
    }

    pub type MaybeWorkspaceVecString = MaybeWorkspace<Vec<String>, TomlWorkspaceField>;
    impl<'de> de::Deserialize<'de> for MaybeWorkspaceVecString {
        fn deserialize<D>(d: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            struct Visitor;

            impl<'de> de::Visitor<'de> for Visitor {
                type Value = MaybeWorkspaceVecString;

                fn expecting(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
                    f.write_str("a vector of strings or workspace")
                }
                fn visit_seq<A>(self, v: A) -> Result<Self::Value, A::Error>
                where
                    A: de::SeqAccess<'de>,
                {
                    let seq = de::value::SeqAccessDeserializer::new(v);
                    Vec::deserialize(seq).map(MaybeWorkspace::Defined)
                }

                fn visit_map<V>(self, map: V) -> Result<Self::Value, V::Error>
                where
                    V: de::MapAccess<'de>,
                {
                    let mvd = de::value::MapAccessDeserializer::new(map);
                    TomlWorkspaceField::deserialize(mvd).map(MaybeWorkspace::Workspace)
                }
            }

            d.deserialize_any(Visitor)
        }
    }

    pub type MaybeWorkspaceStringOrBool = MaybeWorkspace<StringOrBool, TomlWorkspaceField>;
    impl<'de> de::Deserialize<'de> for MaybeWorkspaceStringOrBool {
        fn deserialize<D>(d: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            struct Visitor;

            impl<'de> de::Visitor<'de> for Visitor {
                type Value = MaybeWorkspaceStringOrBool;

                fn expecting(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
                    f.write_str("a string, a bool, or workspace")
                }

                fn visit_bool<E>(self, v: bool) -> Result<Self::Value, E>
                where
                    E: de::Error,
                {
                    let b = de::value::BoolDeserializer::new(v);
                    StringOrBool::deserialize(b).map(MaybeWorkspace::Defined)
                }

                fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
                where
                    E: de::Error,
                {
                    let string = de::value::StringDeserializer::new(v);
                    StringOrBool::deserialize(string).map(MaybeWorkspace::Defined)
                }

                fn visit_map<V>(self, map: V) -> Result<Self::Value, V::Error>
                where
                    V: de::MapAccess<'de>,
                {
                    let mvd = de::value::MapAccessDeserializer::new(map);
                    TomlWorkspaceField::deserialize(mvd).map(MaybeWorkspace::Workspace)
                }
            }

            d.deserialize_any(Visitor)
        }
    }

    pub type MaybeWorkspaceVecStringOrBool = MaybeWorkspace<VecStringOrBool, TomlWorkspaceField>;
    impl<'de> de::Deserialize<'de> for MaybeWorkspaceVecStringOrBool {
        fn deserialize<D>(d: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            struct Visitor;

            impl<'de> de::Visitor<'de> for Visitor {
                type Value = MaybeWorkspaceVecStringOrBool;

                fn expecting(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
                    f.write_str("a boolean, a vector of strings, or workspace")
                }

                fn visit_bool<E>(self, v: bool) -> Result<Self::Value, E>
                where
                    E: de::Error,
                {
                    let b = de::value::BoolDeserializer::new(v);
                    VecStringOrBool::deserialize(b).map(MaybeWorkspace::Defined)
                }

                fn visit_seq<A>(self, v: A) -> Result<Self::Value, A::Error>
                where
                    A: de::SeqAccess<'de>,
                {
                    let seq = de::value::SeqAccessDeserializer::new(v);
                    VecStringOrBool::deserialize(seq).map(MaybeWorkspace::Defined)
                }

                fn visit_map<V>(self, map: V) -> Result<Self::Value, V::Error>
                where
                    V: de::MapAccess<'de>,
                {
                    let mvd = de::value::MapAccessDeserializer::new(map);
                    TomlWorkspaceField::deserialize(mvd).map(MaybeWorkspace::Workspace)
                }
            }

            d.deserialize_any(Visitor)
        }
    }

    pub type MaybeWorkspaceBtreeMap =
        MaybeWorkspace<BTreeMap<String, BTreeMap<String, String>>, TomlWorkspaceField>;

    impl<'de> de::Deserialize<'de> for MaybeWorkspaceBtreeMap {
        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            let value = serde_value::Value::deserialize(deserializer)?;

            if let Ok(w) = TomlWorkspaceField::deserialize(
                serde_value::ValueDeserializer::<D::Error>::new(value.clone()),
            ) {
                return if w.workspace {
                    Ok(MaybeWorkspace::Workspace(w))
                } else {
                    Err(de::Error::custom("`workspace` cannot be false"))
                };
            }
            BTreeMap::deserialize(serde_value::ValueDeserializer::<D::Error>::new(value))
                .map(MaybeWorkspace::Defined)
        }
    }

    #[derive(Deserialize, Serialize, Copy, Clone, Debug)]
    #[serde(rename_all = "kebab-case")]
    pub struct TomlWorkspaceField {
        #[serde(deserialize_with = "bool_no_false")]
        pub workspace: bool,
    }

    fn bool_no_false<'de, D: de::Deserializer<'de>>(deserializer: D) -> Result<bool, D::Error> {
        let b: bool = Deserialize::deserialize(deserializer)?;
        if b {
            Ok(b)
        } else {
            Err(de::Error::custom("`workspace` cannot be false"))
        }
    }

    pub type MaybeWorkspaceDependency = MaybeWorkspace<TomlDependency, TomlWorkspaceDependency>;

    impl MaybeWorkspaceDependency {
        pub fn unused_keys(&self) -> Vec<String> {
            match self {
                MaybeWorkspaceDependency::Defined(d) => d.unused_keys(),
                MaybeWorkspaceDependency::Workspace(w) => w.unused_keys.keys().cloned().collect(),
            }
        }
    }

    impl<'de> de::Deserialize<'de> for MaybeWorkspaceDependency {
        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            let value = serde_value::Value::deserialize(deserializer)?;

            if let Ok(w) = TomlWorkspaceDependency::deserialize(serde_value::ValueDeserializer::<
                D::Error,
            >::new(value.clone()))
            {
                return if w.workspace {
                    Ok(MaybeWorkspace::Workspace(w))
                } else {
                    Err(de::Error::custom("`workspace` cannot be false"))
                };
            }
            TomlDependency::deserialize(serde_value::ValueDeserializer::<D::Error>::new(value))
                .map(MaybeWorkspace::Defined)
        }
    }

    #[derive(Deserialize, Serialize, Clone, Debug)]
    #[serde(rename_all = "kebab-case")]
    pub struct TomlWorkspaceDependency {
        pub workspace: bool,
        pub features: Option<Vec<String>>,
        pub default_features: Option<bool>,
        #[serde(rename = "default_features")]
        pub default_features2: Option<bool>,
        pub optional: Option<bool>,
        pub public: Option<bool>,

        /// This is here to provide a way to see the "unused manifest keys" when deserializing
        #[serde(skip_serializing)]
        #[serde(flatten)]
        pub unused_keys: BTreeMap<String, toml::Value>,
    }

    impl TomlWorkspaceDependency {
        pub fn default_features(&self) -> Option<bool> {
            self.default_features.or(self.default_features2)
        }
    }

    #[derive(Clone, Debug, Serialize)]
    #[serde(untagged)]
    pub enum TomlDependency<P: Clone = String> {
        /// In the simple format, only a version is specified, eg.
        /// `package = "<version>"`
        Simple(String),
        /// The simple format is equivalent to a detailed dependency
        /// specifying only a version, eg.
        /// `package = { version = "<version>" }`
        Detailed(DetailedTomlDependency<P>),
    }

    impl TomlDependency {
        pub fn is_version_specified(&self) -> bool {
            match self {
                TomlDependency::Detailed(d) => d.version.is_some(),
                TomlDependency::Simple(..) => true,
            }
        }

        pub fn is_optional(&self) -> bool {
            match self {
                TomlDependency::Detailed(d) => d.optional.unwrap_or(false),
                TomlDependency::Simple(..) => false,
            }
        }

        pub fn unused_keys(&self) -> Vec<String> {
            match self {
                TomlDependency::Simple(_) => vec![],
                TomlDependency::Detailed(detailed) => detailed.unused_keys.keys().cloned().collect(),
            }
        }
    }

    impl<'de, P: Deserialize<'de> + Clone> de::Deserialize<'de> for TomlDependency<P> {
        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            UntaggedEnumVisitor::new()
                .expecting(
                    "a version string like \"0.9.8\" or a \
                         detailed dependency like { version = \"0.9.8\" }",
                )
                .string(|value| Ok(TomlDependency::Simple(value.to_owned())))
                .map(|value| value.deserialize().map(TomlDependency::Detailed))
                .deserialize(deserializer)
        }
    }

    #[derive(Deserialize, Serialize, Clone, Debug)]
    #[serde(rename_all = "kebab-case")]
    pub struct DetailedTomlDependency<P: Clone = String> {
        pub version: Option<String>,
        pub registry: Option<String>,
        /// The URL of the `registry` field.
        /// This is an internal implementation detail. When Cargo creates a
        /// package, it replaces `registry` with `registry-index` so that the
        /// manifest contains the correct URL. All users won't have the same
        /// registry names configured, so Cargo can't rely on just the name for
        /// crates published by other users.
        pub registry_index: Option<String>,
        // `path` is relative to the file it appears in. If that's a `Cargo.toml`, it'll be relative to
        // that TOML file, and if it's a `.cargo/config` file, it'll be relative to that file.
        pub path: Option<P>,
        pub git: Option<String>,
        pub branch: Option<String>,
        pub tag: Option<String>,
        pub rev: Option<String>,
        pub features: Option<Vec<String>>,
        pub optional: Option<bool>,
        pub default_features: Option<bool>,
        #[serde(rename = "default_features")]
        pub default_features2: Option<bool>,
        pub package: Option<String>,
        pub public: Option<bool>,

        /// One or more of `bin`, `cdylib`, `staticlib`, `bin:<name>`.
        pub artifact: Option<StringOrVec>,
        /// If set, the artifact should also be a dependency
        pub lib: Option<bool>,
        /// A platform name, like `x86_64-apple-darwin`
        pub target: Option<String>,

        /// This is here to provide a way to see the "unused manifest keys" when deserializing
        #[serde(skip_serializing)]
        #[serde(flatten)]
        pub unused_keys: BTreeMap<String, toml::Value>,
    }

    impl<P: Clone> DetailedTomlDependency<P> {
        pub fn default_features(&self) -> Option<bool> {
            self.default_features.or(self.default_features2)
        }
    }

    // Explicit implementation so we avoid pulling in P: Default
    impl<P: Clone> Default for DetailedTomlDependency<P> {
        fn default() -> Self {
            Self {
                version: Default::default(),
                registry: Default::default(),
                registry_index: Default::default(),
                path: Default::default(),
                git: Default::default(),
                branch: Default::default(),
                tag: Default::default(),
                rev: Default::default(),
                features: Default::default(),
                optional: Default::default(),
                default_features: Default::default(),
                default_features2: Default::default(),
                package: Default::default(),
                public: Default::default(),
                artifact: Default::default(),
                lib: Default::default(),
                target: Default::default(),
                unused_keys: Default::default(),
            }
        }
    }

    #[derive(Deserialize, Serialize, Clone, Debug, Default)]
    pub struct TomlProfiles(pub BTreeMap<String, TomlProfile>);

    impl TomlProfiles {
        pub fn get_all(&self) -> &BTreeMap<String, TomlProfile> {
            &self.0
        }

        pub fn get(&self, name: &str) -> Option<&TomlProfile> {
            self.0.get(name)
        }
    }

    #[derive(Deserialize, Serialize, Clone, Debug, Default, Eq, PartialEq)]
    #[serde(default, rename_all = "kebab-case")]
    pub struct TomlProfile {
        pub opt_level: Option<TomlOptLevel>,
        pub lto: Option<StringOrBool>,
        pub codegen_backend: Option<String>,
        pub codegen_units: Option<u32>,
        pub debug: Option<TomlDebugInfo>,
        pub split_debuginfo: Option<String>,
        pub debug_assertions: Option<bool>,
        pub rpath: Option<bool>,
        pub panic: Option<String>,
        pub overflow_checks: Option<bool>,
        pub incremental: Option<bool>,
        pub dir_name: Option<String>,
        pub inherits: Option<String>,
        pub strip: Option<StringOrBool>,
        // Note that `rustflags` is used for the cargo-feature `profile_rustflags`
        pub rustflags: Option<Vec<String>>,
        // These two fields must be last because they are sub-tables, and TOML
        // requires all non-tables to be listed first.
        pub package: Option<BTreeMap<ProfilePackageSpec, TomlProfile>>,
        pub build_override: Option<Box<TomlProfile>>,
        /// Unstable feature `-Ztrim-paths`.
        pub trim_paths: Option<TomlTrimPaths>,
    }

    #[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
    pub enum ProfilePackageSpec {
        Spec(PackageIdSpec),
        All,
    }

    impl fmt::Display for ProfilePackageSpec {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            match self {
                ProfilePackageSpec::Spec(spec) => spec.fmt(f),
                ProfilePackageSpec::All => f.write_str("*"),
            }
        }
    }

    impl ser::Serialize for ProfilePackageSpec {
        fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
        where
            S: ser::Serializer,
        {
            self.to_string().serialize(s)
        }
    }

    impl<'de> de::Deserialize<'de> for ProfilePackageSpec {
        fn deserialize<D>(d: D) -> Result<ProfilePackageSpec, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            let string = String::deserialize(d)?;
            if string == "*" {
                Ok(ProfilePackageSpec::All)
            } else {
                PackageIdSpec::parse(&string)
                    .map_err(de::Error::custom)
                    .map(ProfilePackageSpec::Spec)
            }
        }
    }

    #[derive(Clone, Debug, Eq, PartialEq)]
    pub struct TomlOptLevel(pub String);

    impl ser::Serialize for TomlOptLevel {
        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
        where
            S: ser::Serializer,
        {
            match self.0.parse::<u32>() {
                Ok(n) => n.serialize(serializer),
                Err(_) => self.0.serialize(serializer),
            }
        }
    }

    impl<'de> de::Deserialize<'de> for TomlOptLevel {
        fn deserialize<D>(d: D) -> Result<TomlOptLevel, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            use serde::de::Error as _;
            UntaggedEnumVisitor::new()
                .expecting("an optimization level")
                .i64(|value| Ok(TomlOptLevel(value.to_string())))
                .string(|value| {
                    if value == "s" || value == "z" {
                        Ok(TomlOptLevel(value.to_string()))
                    } else {
                        Err(serde_untagged::de::Error::custom(format!(
                            "must be `0`, `1`, `2`, `3`, `s` or `z`, \
                             but found the string: \"{}\"",
                            value
                        )))
                    }
                })
                .deserialize(d)
        }
    }

    #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
    pub enum TomlDebugInfo {
        None,
        LineDirectivesOnly,
        LineTablesOnly,
        Limited,
        Full,
    }

    impl Display for TomlDebugInfo {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            match self {
                TomlDebugInfo::None => f.write_char('0'),
                TomlDebugInfo::Limited => f.write_char('1'),
                TomlDebugInfo::Full => f.write_char('2'),
                TomlDebugInfo::LineDirectivesOnly => f.write_str("line-directives-only"),
                TomlDebugInfo::LineTablesOnly => f.write_str("line-tables-only"),
            }
        }
    }

    impl ser::Serialize for TomlDebugInfo {
        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
        where
            S: ser::Serializer,
        {
            match self {
                Self::None => 0.serialize(serializer),
                Self::LineDirectivesOnly => "line-directives-only".serialize(serializer),
                Self::LineTablesOnly => "line-tables-only".serialize(serializer),
                Self::Limited => 1.serialize(serializer),
                Self::Full => 2.serialize(serializer),
            }
        }
    }

    impl<'de> de::Deserialize<'de> for TomlDebugInfo {
        fn deserialize<D>(d: D) -> Result<TomlDebugInfo, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            use serde::de::Error as _;
            let expecting = "a boolean, 0, 1, 2, \"line-tables-only\", or \"line-directives-only\"";
            UntaggedEnumVisitor::new()
                .expecting(expecting)
                .bool(|value| {
                    Ok(if value {
                        TomlDebugInfo::Full
                    } else {
                        TomlDebugInfo::None
                    })
                })
                .i64(|value| {
                    let debuginfo = match value {
                        0 => TomlDebugInfo::None,
                        1 => TomlDebugInfo::Limited,
                        2 => TomlDebugInfo::Full,
                        _ => {
                            return Err(serde_untagged::de::Error::invalid_value(
                                Unexpected::Signed(value),
                                &expecting,
                            ))
                        }
                    };
                    Ok(debuginfo)
                })
                .string(|value| {
                    let debuginfo = match value {
                        "none" => TomlDebugInfo::None,
                        "limited" => TomlDebugInfo::Limited,
                        "full" => TomlDebugInfo::Full,
                        "line-directives-only" => TomlDebugInfo::LineDirectivesOnly,
                        "line-tables-only" => TomlDebugInfo::LineTablesOnly,
                        _ => {
                            return Err(serde_untagged::de::Error::invalid_value(
                                Unexpected::Str(value),
                                &expecting,
                            ))
                        }
                    };
                    Ok(debuginfo)
                })
                .deserialize(d)
        }
    }

    #[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash, Serialize)]
    #[serde(untagged, rename_all = "kebab-case")]
    pub enum TomlTrimPaths {
        Values(Vec<TomlTrimPathsValue>),
        All,
    }

    impl TomlTrimPaths {
        pub fn none() -> Self {
            TomlTrimPaths::Values(Vec::new())
        }

        pub fn is_none(&self) -> bool {
            match self {
                TomlTrimPaths::Values(v) => v.is_empty(),
                TomlTrimPaths::All => false,
            }
        }
    }

    impl<'de> de::Deserialize<'de> for TomlTrimPaths {
        fn deserialize<D>(d: D) -> Result<TomlTrimPaths, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            use serde::de::Error as _;
            let expecting = r#"a boolean, "none", "diagnostics", "macro", "object", "all", or an array with these options"#;
            UntaggedEnumVisitor::new()
                .expecting(expecting)
                .bool(|value| {
                    Ok(if value {
                        TomlTrimPaths::All
                    } else {
                        TomlTrimPaths::none()
                    })
                })
                .string(|v| match v {
                    "none" => Ok(TomlTrimPaths::none()),
                    "all" => Ok(TomlTrimPaths::All),
                    v => {
                        let d = v.into_deserializer();
                        let err = |_: D::Error| {
                            serde_untagged::de::Error::custom(format!("expected {expecting}"))
                        };
                        TomlTrimPathsValue::deserialize(d)
                            .map_err(err)
                            .map(|v| v.into())
                    }
                })
                .seq(|seq| {
                    let seq: Vec<String> = seq.deserialize()?;
                    let seq: Vec<_> = seq
                        .into_iter()
                        .map(|s| TomlTrimPathsValue::deserialize(s.into_deserializer()))
                        .collect::<Result<_, _>>()?;
                    Ok(seq.into())
                })
                .deserialize(d)
        }
    }

    impl fmt::Display for TomlTrimPaths {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            match self {
                TomlTrimPaths::All => write!(f, "all"),
                TomlTrimPaths::Values(v) if v.is_empty() => write!(f, "none"),
                TomlTrimPaths::Values(v) => {
                    let mut iter = v.iter();
                    if let Some(value) = iter.next() {
                        write!(f, "{value}")?;
                    }
                    for value in iter {
                        write!(f, ",{value}")?;
                    }
                    Ok(())
                }
            }
        }
    }

    impl From<TomlTrimPathsValue> for TomlTrimPaths {
        fn from(value: TomlTrimPathsValue) -> Self {
            TomlTrimPaths::Values(vec![value])
        }
    }

    impl From<Vec<TomlTrimPathsValue>> for TomlTrimPaths {
        fn from(value: Vec<TomlTrimPathsValue>) -> Self {
            TomlTrimPaths::Values(value)
        }
    }

    #[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
    #[serde(rename_all = "kebab-case")]
    pub enum TomlTrimPathsValue {
        Diagnostics,
        Macro,
        Object,
    }

    impl TomlTrimPathsValue {
        pub fn as_str(&self) -> &'static str {
            match self {
                TomlTrimPathsValue::Diagnostics => "diagnostics",
                TomlTrimPathsValue::Macro => "macro",
                TomlTrimPathsValue::Object => "object",
            }
        }
    }

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

    pub type TomlLibTarget = TomlTarget;
    pub type TomlBinTarget = TomlTarget;
    pub type TomlExampleTarget = TomlTarget;
    pub type TomlTestTarget = TomlTarget;
    pub type TomlBenchTarget = TomlTarget;

    #[derive(Default, Serialize, Deserialize, Debug, Clone)]
    #[serde(rename_all = "kebab-case")]
    pub struct TomlTarget {
        pub name: Option<String>,

        // The intention was to only accept `crate-type` here but historical
        // versions of Cargo also accepted `crate_type`, so look for both.
        pub crate_type: Option<Vec<String>>,
        #[serde(rename = "crate_type")]
        pub crate_type2: Option<Vec<String>>,

        pub path: Option<PathValue>,
        // Note that `filename` is used for the cargo-feature `different_binary_name`
        pub filename: Option<String>,
        pub test: Option<bool>,
        pub doctest: Option<bool>,
        pub bench: Option<bool>,
        pub doc: Option<bool>,
        pub plugin: Option<bool>,
        pub doc_scrape_examples: Option<bool>,
        #[serde(rename = "proc-macro")]
        pub proc_macro_raw: Option<bool>,
        #[serde(rename = "proc_macro")]
        pub proc_macro_raw2: Option<bool>,
        pub harness: Option<bool>,
        pub required_features: Option<Vec<String>>,
        pub edition: Option<String>,
    }

    impl TomlTarget {
        pub fn new() -> TomlTarget {
            TomlTarget::default()
        }

        pub fn proc_macro(&self) -> Option<bool> {
            self.proc_macro_raw.or(self.proc_macro_raw2).or_else(|| {
                if let Some(types) = self.crate_types() {
                    if types.contains(&"proc-macro".to_string()) {
                        return Some(true);
                    }
                }
                None
            })
        }

        pub fn crate_types(&self) -> Option<&Vec<String>> {
            self.crate_type
                .as_ref()
                .or_else(|| self.crate_type2.as_ref())
        }
    }

    /// Corresponds to a `target` entry, but `TomlTarget` is already used.
    #[derive(Serialize, Deserialize, Debug, Clone)]
    #[serde(rename_all = "kebab-case")]
    pub struct TomlPlatform {
        pub dependencies: Option<BTreeMap<String, MaybeWorkspaceDependency>>,
        pub build_dependencies: Option<BTreeMap<String, MaybeWorkspaceDependency>>,
        #[serde(rename = "build_dependencies")]
        pub build_dependencies2: Option<BTreeMap<String, MaybeWorkspaceDependency>>,
        pub dev_dependencies: Option<BTreeMap<String, MaybeWorkspaceDependency>>,
        #[serde(rename = "dev_dependencies")]
        pub dev_dependencies2: Option<BTreeMap<String, MaybeWorkspaceDependency>>,
    }

    impl TomlPlatform {
        pub fn dev_dependencies(&self) -> Option<&BTreeMap<String, MaybeWorkspaceDependency>> {
            self.dev_dependencies
                .as_ref()
                .or(self.dev_dependencies2.as_ref())
        }

        pub fn build_dependencies(&self) -> Option<&BTreeMap<String, MaybeWorkspaceDependency>> {
            self.build_dependencies
                .as_ref()
                .or(self.build_dependencies2.as_ref())
        }
    }

    #[derive(Deserialize, Serialize, Debug, Clone)]
    #[serde(expecting = "a lints table")]
    #[serde(rename_all = "kebab-case")]
    pub struct MaybeWorkspaceLints {
        #[serde(skip_serializing_if = "is_false")]
        #[serde(deserialize_with = "bool_no_false", default)]
        pub workspace: bool,
        #[serde(flatten)]
        pub lints: TomlLints,
    }

    fn is_false(b: &bool) -> bool {
        !b
    }

    pub type TomlLints = BTreeMap<String, TomlToolLints>;

    pub type TomlToolLints = BTreeMap<String, TomlLint>;

    #[derive(Serialize, Debug, Clone)]
    #[serde(untagged)]
    pub enum TomlLint {
        Level(TomlLintLevel),
        Config(TomlLintConfig),
    }

    impl<'de> Deserialize<'de> for TomlLint {
        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            UntaggedEnumVisitor::new()
                .string(|string| {
                    TomlLintLevel::deserialize(string.into_deserializer()).map(TomlLint::Level)
                })
                .map(|map| map.deserialize().map(TomlLint::Config))
                .deserialize(deserializer)
        }
    }

    impl TomlLint {
        pub fn level(&self) -> TomlLintLevel {
            match self {
                Self::Level(level) => *level,
                Self::Config(config) => config.level,
            }
        }

        pub fn priority(&self) -> i8 {
            match self {
                Self::Level(_) => 0,
                Self::Config(config) => config.priority,
            }
        }
    }

    #[derive(Serialize, Deserialize, Debug, Clone)]
    #[serde(rename_all = "kebab-case")]
    pub struct TomlLintConfig {
        pub level: TomlLintLevel,
        #[serde(default)]
        pub priority: i8,
    }

    #[derive(Serialize, Deserialize, Debug, Copy, Clone)]
    #[serde(rename_all = "kebab-case")]
    pub enum TomlLintLevel {
        Forbid,
        Deny,
        Warn,
        Allow,
    }

    #[derive(Copy, Clone, Debug)]
    pub struct InvalidCargoFeatures {}

    impl<'de> de::Deserialize<'de> for InvalidCargoFeatures {
        fn deserialize<D>(_d: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            use serde::de::Error as _;

            Err(D::Error::custom(
                "the field `cargo-features` should be set at the top of Cargo.toml before any tables",
            ))
        }
    }

    /// A StringOrVec can be parsed from either a TOML string or array,
    /// but is always stored as a vector.
    #[derive(Clone, Debug, Serialize, Eq, PartialEq, PartialOrd, Ord)]
    pub struct StringOrVec(pub Vec<String>);

    impl StringOrVec {
        pub fn iter<'a>(&'a self) -> std::slice::Iter<'a, String> {
            self.0.iter()
        }
    }

    impl<'de> de::Deserialize<'de> for StringOrVec {
        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            UntaggedEnumVisitor::new()
                .expecting("string or list of strings")
                .string(|value| Ok(StringOrVec(vec![value.to_owned()])))
                .seq(|value| value.deserialize().map(StringOrVec))
                .deserialize(deserializer)
        }
    }

    #[derive(Clone, Debug, Serialize, Eq, PartialEq)]
    #[serde(untagged)]
    pub enum StringOrBool {
        String(String),
        Bool(bool),
    }

    impl<'de> Deserialize<'de> for StringOrBool {
        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            UntaggedEnumVisitor::new()
                .bool(|b| Ok(StringOrBool::Bool(b)))
                .string(|s| Ok(StringOrBool::String(s.to_owned())))
                .deserialize(deserializer)
        }
    }

    #[derive(PartialEq, Clone, Debug, Serialize)]
    #[serde(untagged)]
    pub enum VecStringOrBool {
        VecString(Vec<String>),
        Bool(bool),
    }

    impl<'de> de::Deserialize<'de> for VecStringOrBool {
        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            UntaggedEnumVisitor::new()
                .expecting("a boolean or vector of strings")
                .bool(|value| Ok(VecStringOrBool::Bool(value)))
                .seq(|value| value.deserialize().map(VecStringOrBool::VecString))
                .deserialize(deserializer)
        }
    }

    #[derive(Clone)]
    pub struct PathValue(pub PathBuf);

    impl fmt::Debug for PathValue {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            self.0.fmt(f)
        }
    }

    impl ser::Serialize for PathValue {
        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
        where
            S: ser::Serializer,
        {
            self.0.serialize(serializer)
        }
    }

    impl<'de> de::Deserialize<'de> for PathValue {
        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            Ok(PathValue(String::deserialize(deserializer)?.into()))
        }
    }