Skip to content

Commit

Permalink
Merge pull request #680 from jonasbb/cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb committed Jan 20, 2024
2 parents 6553804 + 4f1a619 commit cc06ba2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 24 deletions.
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,31 @@

"cSpell.words": [
"accu",
"alloc",
"binhex",
"Boollike",
"btreemap",
"btreeset",
"chrono",
"clippy",
"codecov",
"concat",
"constgeneric",
"datetime",
"deps",
"Deque",
"deserializable",
"Deserialization",
"Deserializes",
"docsrs",
"elems",
"fromstr",
"hashbrown",
"hasher",
"hashset",
"impls",
"indexmap",
"jsonschema",
"linkedlist",
"markazmierczak",
"Milli",
Expand All @@ -41,13 +47,16 @@
"newtype",
"nsecs",
"rustdoc",
"Rustexplorer",
"rustfmt",
"RUSTSEC",
"rustversion",
"schemars",
"serde",
"serde's",
"serializable",
"serializers",
"smoketest",
"struct",
"structs",
"subsec",
Expand Down
22 changes: 11 additions & 11 deletions serde_with/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ guide = ["dep:doc-comment", "dep:document-features", "macros", "std"]
#! # 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 miniminze the amount of required dependencies.
#! These features are disabled by default to minimize the amount of required dependencies.

## The feature enables serializing data in base64 format.
base64 = ["dep:base64", "alloc"]
Expand All @@ -63,11 +63,11 @@ chrono = ["chrono_0_4"]
## 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 compatability.
## The legacy feature name `chrono` is still available for v1 compatibility.
##
## This pulls in `chrono` v0.4 as a dependency.
chrono_0_4 = ["dep:chrono_0_4"]
## The feature enables `hashbown::{HashMap, HashSet}` as supported containers.
## The feature enables `hashbrown::{HashMap, HashSet}` as supported containers.
##
## This pulls in `hashbrown` v0.14 as a dependency.
## It enables the `alloc` feature.
Expand All @@ -82,7 +82,7 @@ hex = ["dep:hex", "alloc"]
indexmap = ["indexmap_1"]
## 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 compatability.
## The legacy feature name `indexmap` is still available for v1 compatibility.
##
## This pulls in `indexmap` v1 as a dependency.
## It enables the `alloc` feature.
Expand All @@ -105,19 +105,19 @@ json = ["dep:serde_json", "alloc"]
##
## This pulls in `serde_with_macros` as a dependency.
macros = ["dep:serde_with_macros"]
## 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.
time_0_3 = ["dep:time_0_3"]
## 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]`.
schemars_0_8 = ["dep:schemars_0_8", "std", "serde_with_macros?/schemars_0_8"]
## 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.
time_0_3 = ["dep:time_0_3"]

# When adding new optional dependencies update the documentation in feature-flags.md
[dependencies]
Expand All @@ -129,13 +129,13 @@ hashbrown_0_14 = {package = "hashbrown", version = "0.14.0", optional = true, de
hex = {version = "0.4.3", optional = true, default-features = false}
indexmap_1 = {package = "indexmap", version = "1.8", optional = true, default-features = false, features = ["serde-1"]}
indexmap_2 = {package = "indexmap", version = "2.0", optional = true, default-features = false, features = ["serde"]}
schemars_0_8 = {package = "schemars", version = "0.8.16", optional = true, default-features = false}
# The derive feature is needed for the flattened_maybe macro.
# https://github.com/jonasbb/serde_with/blob/eb1965a74a3be073ecd13ec05f02a01bc1c44309/serde_with/src/flatten_maybe.rs#L67
serde = {version = "1.0.152", default-features = false, features = ["derive"] }
serde_json = {version = "1.0.45", optional = true, default-features = false}
serde_with_macros = {path = "../serde_with_macros", version = "=3.4.0", optional = true}
time_0_3 = {package = "time", version = "~0.3.11", optional = true, default-features = false}
schemars_0_8 = {package = "schemars", version = "0.8.16", optional = true, default-features = false}

[dev-dependencies]
expect-test = "1.3.0"
Expand Down
18 changes: 10 additions & 8 deletions serde_with/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ pub struct As<T: ?Sized>(PhantomData<T>);
/// Adapter to convert from `serde_as` to the serde traits.
///
/// This is the counter-type to [`As`][].
/// It can be used whenever a type implementing [`DeserializeAs`][]/[`SerializeAs`][] is required but the normal `Deserialize`/`Serialize` traits should be used.
/// It can be used whenever a type implementing [`DeserializeAs`]/[`SerializeAs`] is required but the normal [`Deserialize`](::serde::Deserialize)/[`Serialize`](::serde::Serialize) traits should be used.
/// Check [`As`] for an example.
pub struct Same;

Expand Down Expand Up @@ -558,7 +558,7 @@ pub struct DisplayFromStr;

/// De/Serialize a [`Option<String>`] type while transforming the empty string to [`None`]
///
/// Convert an [`Option<T>`] from/to string using [`FromStr`] and [`Display`] implementations.
/// Convert an [`Option<T>`] from/to string using [`FromStr`] and [`Display`](::core::fmt::Display) implementations.
/// An empty string is deserialized as [`None`] and a [`None`] vice versa.
///
/// # Examples
Expand Down Expand Up @@ -1636,8 +1636,11 @@ pub struct Bytes;
/// This distinction is not semantically important on the Rust side, thus both forms should deserialize into the same `Vec`.
///
/// The `OneOrMany` adapter achieves exactly this use case.
/// The serialization behavior can be tweaked to either always serialize as a list using `PreferMany` or to serialize as the inner element if possible using `PreferOne`.
/// By default, `PreferOne` is assumed, which can also be omitted like `OneOrMany<_>`.
/// The serialization behavior can be tweaked to either always serialize as a list using [`PreferMany`] or to serialize as the inner element if possible using [`PreferOne`].
/// By default, [`PreferOne`] is assumed, which can also be omitted like `OneOrMany<_>`.
///
/// [`PreferMany`]: crate::formats::PreferMany
/// [`PreferOne`]: crate::formats::PreferOne
///
/// # Examples
///
Expand Down Expand Up @@ -1768,7 +1771,7 @@ pub struct PickFirst<T>(PhantomData<T>);
/// For deserialization the opposite `T: Into<O>` is required.
/// The `Clone` bound is required since `serialize` operates on a reference but `Into` implementations on references are uncommon.
///
/// **Note**: [`TryFromInto`] is the more generalized version of this adapter which uses the [`TryInto`](std::convert::TryInto) trait instead.
/// **Note**: [`TryFromInto`] is the more generalized version of this adapter which uses the [`TryInto`] trait instead.
///
/// # Example
///
Expand Down Expand Up @@ -1849,7 +1852,7 @@ pub struct FromInto<T>(PhantomData<T>);
/// For serialization `O` needs to be `for<'a> &'a O: Into<T>`.
/// For deserialization the opposite `T: Into<O>` is required.
///
/// **Note**: [`TryFromIntoRef`] is the more generalized version of this adapter which uses the [`TryInto`](std::convert::TryInto) trait instead.
/// **Note**: [`TryFromIntoRef`] is the more generalized version of this adapter which uses the [`TryInto`] trait instead.
///
/// # Example
///
Expand Down Expand Up @@ -2518,10 +2521,9 @@ pub struct SetLastValueWins<T>(PhantomData<T>);
/// Helper for implementing [`JsonSchema`] on serializers whose output depends
/// on the type of the concrete field.
///
/// It is added implicitly by the [`#[serde_as]`] macro when any `schemars`
/// It is added implicitly by the [`#[serde_as]`](crate::serde_as) macro when any `schemars`
/// feature is enabled.
///
/// [`JsonSchema`]: ::schemars_0_8::JsonSchema
/// [`#[serde_as]`]: crate::serde_as
#[cfg(feature = "schemars_0_8")]
pub struct Schema<T: ?Sized, TA>(PhantomData<T>, PhantomData<TA>);
2 changes: 1 addition & 1 deletion serde_with/src/schemars_0_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub trait JsonSchemaAs<T: ?Sized> {
/// Generates a JSON Schema for this type.
///
/// If the returned schema depends on any [referenceable](JsonSchema::is_referenceable) schemas, then this method will
/// add them to the [`SchemaGenerator`](gen::SchemaGenerator)'s schema definitions.
/// add them to the [`SchemaGenerator`]'s schema definitions.
///
/// This should not return a `$ref` schema.
fn json_schema(gen: &mut SchemaGenerator) -> Schema;
Expand Down
4 changes: 3 additions & 1 deletion serde_with/src/serde_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
/// 2. The type `T` we want to extend with custom behavior.
/// 3. A function or macro taking a `&T` and returning a serializable type.
/// 4. A function or macro taking a deserializable type and returning a `Result<T, E>`.
/// The error type `E` must implement `Display`.
/// The error type `E` must implement [`Display`].
///
/// [`Display`]: std::fmt::Display
///
/// # Example
///
Expand Down
3 changes: 3 additions & 0 deletions serde_with/src/time_0_3.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! De/Serialization of [time v0.3][time] types
//!
//! This modules is only available if using the `time_0_3` feature of the crate.
//! No extra types are exposed. Instead it enables support for [`time_0_3::Duration`] together with [`DurationSeconds`] and its variants.
//! The types [`time_0_3::PrimitiveDateTime`] and [`time_0_3::OffsetDateTime`] are supported by [`TimestampSeconds`] and its variants.
//! The well-known format descriptions [`Rfc2822`], [`Rfc3339`] and [`Iso8601`] are supported for [`OffsetDateTime`].
//!
//! [time]: https://docs.rs/time/0.3/

Expand Down
6 changes: 3 additions & 3 deletions serde_with_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ where
/// The `serialize_always` cannot be used together with a manual `skip_serializing_if` annotations,
/// as these conflict in their meaning. A compile error will be generated if this occurs.
///
/// The `skip_serializing_none` only works if the type is called [`Option`],
/// [`std::option::Option`], or [`core::option::Option`]. Type aliasing an [`Option`] and giving it
/// The `skip_serializing_none` only works if the type is called `Option`,
/// `std::option::Option`, or `core::option::Option`. Type aliasing an [`Option`] and giving it
/// another name, will cause this field to be ignored. This cannot be supported, as proc-macros run
/// before type checking, thus it is not possible to determine if a type alias refers to an
/// [`Option`].
Expand Down Expand Up @@ -565,7 +565,7 @@ fn field_has_attribute(field: &Field, namespace: &str, name: &str) -> bool {
/// For example, using `#[serde_as(as = "NoneAsEmptyString")]` on `Option<String>` will not see
/// any change.
///
/// If the automatically applied attribute is undesired, the behavior can be supressed by adding
/// If the automatically applied attribute is undesired, the behavior can be suppressed by adding
/// `#[serde_as(no_default)]`.

/// This can be combined like `#[serde_as(as = "Option<S>", no_default)]`.
Expand Down

0 comments on commit cc06ba2

Please sign in to comment.