Cargo Features

[dependencies]
serde_with = { version = "3.9.0", default-features = false, features = ["alloc", "std", "guide", "base64", "chrono", "chrono_0_4", "hashbrown_0_14", "hex", "indexmap", "indexmap_1", "indexmap_2", "json", "macros", "schemars_0_8", "time_0_3"] }

When adding new features update the documentation in feature-flags.md The features are documented using https://docs.rs/document-features lib.rs has support for generating the documentation from the feature flags. https://users.rust-lang.org/t/new-features-on-lib-rs/98560

default = macros, std

These default features are set whenever serde_with is added without default-features = false somewhere in the dependency tree.

alloc base64? hashbrown_0_14? hex? indexmap_1? indexmap_2? json? std

serde_with is fully no_std compatible, by depending on it with default-features = false. Support for alloc and std can be enabled with the respective features. Some features require alloc or std support and might not work in a no_std environment.

Enable support for types from the alloc crate when running in a no_std environment.

Enables alloc of optional base64, optional chrono, optional hex, serde, optional serde_json, and optional time

Affects serde_with::DefaultOnError, serde_with::BytesOrString, serde_with::OneOrMany, serde_with::PickFirst, serde_with::BorrowCow, serde_with::VecSkipError, serde_with::MapSkipError, serde_with::MapPreventDuplicates, serde_with::MapFirstKeyWins, serde_with::SetPreventDuplicates, serde_with::SetLastValueWins, rust::sets_duplicate_value_is_error, rust::maps_duplicate_key_is_error, rust::sets_last_value_wins, rust::maps_first_key_wins, utils::size_hint_from_bounds

std default guide? schemars_0_8? = alloc

Enables support for various types from the std library. This will enable std support in all dependencies too. The feature enabled by default and also enables alloc.

Enables clock and std of optional chrono, serde-well-known and std of optional time, std of serde, optional indexmap ^1.8, and optional indexmap

Affects chrono_0_4::datetime_utc_ts_seconds_from_any, serde_with::with_prefix

guide = macros, std

Documentation

The following features enhance the documentation of serde_with.

The guide feature enables inclusion of this user guide. The feature only changes the rustdoc output and enables no other effects.

Enables doc-comment and document-features

base64 = alloc

# Features

The following features enable support for types from other crates or enable additional functionality that requires further dependencies to be pulled in.
These features are disabled by default to minimize the number of required dependencies.

The feature enables serializing data in base64 format.

Enables base64

Affects serde_with::base64

chrono = chrono_0_4

Deprecated feature name. Use chrono_0_4 instead.

Affects serde_with::chrono

chrono_0_4 chrono?

The feature enables integration of chrono v0.4 specific conversions. This includes support for the timestamp and duration types. More features are available in combination with alloc or std. The legacy feature name chrono is still available for v1 compatibility.

This pulls in chrono v0.4 as a dependency.

Enables chrono

Affects serde_with::chrono_0_4

hashbrown_0_14 = alloc

The feature enables hashbrown::{HashMap, HashSet} as supported containers.

This pulls in hashbrown v0.14 as a dependency. It enables the alloc feature. Some functionality is only available when std is enabled too.

Enables hashbrown

hex = alloc

The feature enables serializing data in hex format.

This pulls in hex as a dependency. It enables the alloc feature.

Enables hex

Affects serde_with::hex

indexmap = indexmap_1

Deprecated feature name. Use indexmap_1 instead.

indexmap_1 indexmap? = alloc

The feature enables implementations of indexmap v1 specific checks. This includes support for checking duplicate keys and duplicate values. The legacy feature name indexmap is still available for v1 compatibility.

This pulls in indexmap v1 as a dependency. It enables the alloc feature. Some functionality is only available when std is enabled too.

Enables indexmap ^1.8

indexmap_2 = alloc

The feature enables implementations of indexmap v2 specific checks. This includes support for checking duplicate keys and duplicate values.

This pulls in indexmap v2 as a dependency. It enables the alloc feature. Some functionality is only available when std is enabled too.

Enables indexmap

json = alloc

The feature enables JSON conversions from the json module.

This pulls in serde_json as a dependency. It enables the alloc feature.

Enables serde_json

Affects serde_with::json

macros default guide?

The feature enables all helper macros and derives. It is enabled by default, since the macros provide a usability benefit, especially for serde_as.

This pulls in serde_with_macros as a dependency.

Enables serde_with_macros

schemars_0_8 = std

This feature enables integration with schemars 0.8. This makes #[derive(JsonSchema)] pick up the correct schema for the type used within #[serde_as(as = ...)].

This pulls in schemars v0.8 as a dependency. It will also implicitly enable the std feature as schemars is not #[no_std].

Enables schemars, schemars_0_8 of optional serde_with_macros

Affects serde_with::schemars_0_8, serde_with::Schema

time_0_3

The feature enables integration of time v0.3 specific conversions. This includes support for the timestamp and duration types.

This pulls in time v0.3 as a dependency. Some functionality is only available when alloc or std is enabled too.

Enables time

Affects serde_with::time_0_3

Features from optional dependencies

When adding new optional dependencies, update the documentation in feature-flags.md