Skip to content

Commit

Permalink
Merge #353
Browse files Browse the repository at this point in the history
353: Fix some typos in various places r=jonasbb a=jonasbb

bors merge

Co-authored-by: Jonas Bushart <jonas@bushart.org>
  • Loading branch information
bors[bot] and jonasbb committed Aug 29, 2021
2 parents 577bf96 + 50e23b1 commit 011c778
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 57 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"rustversion",
"serde",
"serde's",
"serializable",
"struct",
"structs",
"subsec",
"subseclen",
Expand All @@ -43,4 +45,8 @@
"rust",
"toml"
],
"cSpell.enabled": true,
"cSpell.ignoreWords": [
"composability"
],
}
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

* Added `PickFirst` adapter for `serde_as`. [#291]
It allows to deserialize from multiple different forms.
It allows deserializing from multiple different forms.
Deserializing a number from either a number or string can be implemented like:

```rust
Expand All @@ -148,7 +148,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed

* Add a new `serde_with::rust::map_as_tuple_list` module as a replacement for `serde_with::rust::btreemap_as_tuple_list` and `serde_with::rust::hashmap_as_tuple_list`.
The new module uses `IntoIterator` and `FromIterator` as trait bound making it usable in more sitations.
The new module uses `IntoIterator` and `FromIterator` as trait bound making it usable in more situations.
The old names continue to exist but are marked as deprecated.

### Deprecated
Expand Down Expand Up @@ -226,14 +226,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
[serde-bytes-complex]: https://github.com/serde-rs/bytes/issues/14
[serde-bytes-arrays]: https://github.com/serde-rs/bytes/issues/26

* The `OneOrMany` allows to deserialize a `Vec` from either a single element or a sequence. ([#281])
* The `OneOrMany` type allows deserializing a `Vec` from either a single element or a sequence. ([#281])

```rust
#[serde_as(as = "OneOrMany<_>")]
cities: Vec<String>,
```

This allows to deserialize from either `cities: "Berlin"` or `cities: ["Berlin", "Paris"]`.
This allows deserializing from either `cities: "Berlin"` or `cities: ["Berlin", "Paris"]`.
The serialization can be configured to always emit a list with `PreferMany` or emit a single element with `PreferOne`.

[#281]: https://github.com/jonasbb/serde_with/pull/281
Expand Down Expand Up @@ -293,7 +293,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed

* Depend on serde with the `derive` feature enabled.
The `derive` feature is required to deserliaze untagged enums which are used in the `DefaultOnError` helpers.
The `derive` feature is required to deserialize untagged enums which are used in the `DefaultOnError` helpers.
This fixes compilation of `serde_with` in scenarios where no other crate enables the `derive` feature.

## [1.5.0] - 2020-10-01
Expand All @@ -318,7 +318,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

This is part of `serde_with_macros` v1.2.0.
* Added some `serialize` functions to modules which previously had none.
This makes it easier to use the conversion when also deriving `Serialialize`.
This makes it easier to use the conversion when also deriving `Serialize`.
The functions simply pass through to the underlying `Serialize` implementation.
This affects `sets_duplicate_value_is_error`, `maps_duplicate_key_is_error`, `maps_first_key_wins`, `default_on_error`, and `default_on_null`.
* Added `sets_last_value_wins` as a replacement for `sets_first_value_wins` which is deprecated now.
Expand Down Expand Up @@ -413,7 +413,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

* Add `skip_serializing_none` attribute, which adds `#[serde(skip_serializing_if = "Option::is_none")]` for each Option in a struct.
This is helpfull for APIs which have many optional fields.
This is helpful for APIs which have many optional fields.
The effect of can be negated by adding `serialize_always` on those fields, which should always be serialized.
Existing `skip_serializing_if` will never be modified and those fields keep their behavior.

Expand Down Expand Up @@ -470,7 +470,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

* `unwrap_or_skip` allows to transparently serialize the inner part of a `Some(T)`
* Add deserialization helpser for sets and maps, inspired by [comment](https://github.com/serde-rs/serde/issues/553#issuecomment-299711855)
* Add deserialization helper for sets and maps, inspired by [comment](https://github.com/serde-rs/serde/issues/553#issuecomment-299711855)
* Create an error if duplicate values for a set are detected
* Create an error if duplicate keys for a map are detected
* Implement a first-value wins strategy for sets/maps. This is different to serde's default
Expand All @@ -490,7 +490,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Add chrono support: Deserialize timestamps from int, float, and string
* Serialization of embedded JSON strings
* De/Serialization using `Display` and `FromStr` implementations
* String-based collections using `Display` and `FromStr`, allows to deserialize "#foo,#bar"
* String-based collections using `Display` and `FromStr`, allows deserializing "#foo,#bar"

## [0.1.0] - 2017-08-17

Expand Down
4 changes: 2 additions & 2 deletions serde_with_macros/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

This should have no effect on the generated code and on the runtime behavior.
It eases integration of third-party crates with `serde_with`, since they can now process the `#[serde_as(...)]` field attributes reliably.
Before this was impossible for derive macros and lead to akward ordering constraints on the attribute macros.
Before this was impossible for derive macros and lead to awkward ordering constraints on the attribute macros.

Thanks to @Lehona for reporting this problem and to @dtolnay for suggesting the dummy derive macro.

Expand Down Expand Up @@ -137,6 +137,6 @@ Initial Release
### Added

* Add `skip_serializing_none` attribute, which adds `#[serde(skip_serializing_if = "Option::is_none")]` for each Option in a struct.
This is helpfull for APIs which have many optional fields.
This is helpful for APIs which have many optional fields.
The effect of can be negated by adding `serialize_always` on those fields, which should always be serialized.
Existing `skip_serializing_if` will never be modified and those fields keep their behavior.
20 changes: 10 additions & 10 deletions serde_with_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ where
/// ```
///
/// The `skip_serializing_if` annotation is repetitive and harms readability.
/// Instead the same struct can be written as:
/// Instead, the same struct can be written as:
///
/// ```rust
/// # use serde::Serialize;
Expand Down Expand Up @@ -394,7 +394,7 @@ fn field_has_attribute(field: &Field, namespace: &str, name: &str) -> bool {

/// Convenience macro to use the [`serde_as`] system.
///
/// The [`serde_as`] system is designed as a more flexible alterative to serde's with-annotation.
/// The [`serde_as`] system is designed as a more flexible alternative to serde's with-annotation.
///
/// # Example
///
Expand Down Expand Up @@ -436,7 +436,7 @@ fn field_has_attribute(field: &Field, namespace: &str, name: &str) -> bool {
/// # What this macro does
///
/// The `serde_as` macro only serves a convenience function.
/// All the steps it takes can easily applied manually, in case the cost of an attribute macro is deemed to high.
/// All the steps it performs, can easily be done manually, in case the cost of an attribute macro is deemed to high.
/// The functionality can best be described with an example.
///
/// ```rust,ignore
Expand All @@ -450,10 +450,10 @@ fn field_has_attribute(field: &Field, namespace: &str, name: &str) -> bool {
///
/// 1. All the placeholder type `_` will be replaced with `::serde_with::Same`.
/// The placeholder type `_` marks all the places where the types `Serialize` implementation should be used.
/// In the example it means that the u32 values will be serialize by the `Serialize` implementation of u32.
/// In the example, it means that the `u32` values will serialize with the `Serialize` implementation of `u32`.
/// The `Same` type implements `SerializeAs` whenever the underlying type implements `Serialize` and is used to make the two traits compatible.
///
/// If you specify a custom path for `serde_with` via the `crate` attribute the path to the `Same` type will be altered accordingly.
/// If you specify a custom path for `serde_with` via the `crate` attribute, the path to the `Same` type will be altered accordingly.
/// 2. Wrap the type from the annotation inside a `::serde_with::As`.
/// In the above example we know have something like `::serde_with::As::<Vec<::serde_with::Same>>`.
/// The `As` type acts as the opposite of the `Same` type.
Expand Down Expand Up @@ -800,11 +800,11 @@ fn has_type_embedded(type_: &Type, embedded_type: &syn::Ident) -> bool {
}
}

/// Deserialize value by using it's [`FromStr`] implementation
/// Deserialize value by using its [`FromStr`] implementation
///
/// This is an alternative way to implement `Deserialize` for types which also implement [`FromStr`] by deserializing the type from string.
/// Ensure that the struct/enum also implements [`FromStr`].
/// If the implementation is missing you will get a error message like
/// If the implementation is missing, you will get an error message like
/// ```text
/// error[E0277]: the trait bound `Struct: std::str::FromStr` is not satisfied
/// ```
Expand Down Expand Up @@ -929,7 +929,7 @@ fn deserialize_fromstr(input: DeriveInput, serde_with_crate_path: Path) -> Token
///
/// This is an alternative way to implement `Serialize` for types which also implement [`Display`] by serializing the type as string.
/// Ensure that the struct/enum also implements [`Display`].
/// If the implementation is missing you will get a error message like
/// If the implementation is missing, you will get an error message like
/// ```text
/// error[E0277]: `Struct` doesn't implement `std::fmt::Display`
/// ```
Expand Down Expand Up @@ -1010,8 +1010,8 @@ fn serialize_display(input: DeriveInput, serde_with_crate_path: Path) -> TokenSt
///
/// The only task of this derive macro is to consume any `serde_as` attributes and turn them into inert attributes.
/// This allows the serde_as macro to keep the field attributes without causing compiler errors.
/// The intend is that keeping the field attributes allows downstream crates to consume and akt on them without causing an ordering dependency to the serde_as macro.
/// Otherwise, downstream proc-macros would need to be places *in front of* the main `#[serde_as]` attribute, since otherwise the field attributes would already be stripped off.
/// The intend is that keeping the field attributes allows downstream crates to consume and act on them without causing an ordering dependency to the serde_as macro.
/// Otherwise, downstream proc-macros would need to be placed *in front of* the main `#[serde_as]` attribute, since otherwise the field attributes would already be stripped off.
///
/// More details about the use-cases in the Github discussion: <https://github.com/jonasbb/serde_with/discussions/260>.
#[proc_macro_derive(__private_consume_serde_as_attributes, attributes(serde_as))]
Expand Down
8 changes: 4 additions & 4 deletions src/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ assert_eq!(data, serde_json::from_str(json).unwrap());
## 2. Integration with serde's with-annotation

[serde's with-annotation][with-annotation] allows to specify a different serialization or deserialization function for a field.
It is usefull to adapt the serialization of existing types to the requirements of a protocol.
It is useful to adapt the serialization of existing types to the requirements of a protocol.
Most modules in this crate can be used together with the with-annotation.

The annotation approach has one big drawback, in that it is very inflexible.
It allows to specify arbitrary serialization code, but the code has to perform the correct transformations.
It allows specifying arbitrary serialization code, but the code has to perform the correct transformations.
It is not possible to combine multiple of those functions.
One common use case for this is the serialization of collections like `Vec`.
If you have a field of type `T`, you can apply the with-annotation, but if you have a field of type `Vec<T>`, there is no way to re-use the same functions for the with-annotation.
Expand Down Expand Up @@ -118,12 +118,12 @@ assert_eq!(data, serde_json::from_str(json).unwrap());

## 3. proc-macros to make it easier to use both above parts

The proc-macros are an optional addition and improve the user exerience for common tasks.
The proc-macros are an optional addition and improve the user experience for common tasks.
We have already seen how the `serde_as` attribute is used to define the serialization instructions.

The proc-macro attributes are defined in the [`serde_with_macros`] crate and re-exported from the root of this crate.
The proc-macros are optional, but enabled by default.
For futher details, please refer to the documentation of each proc-macro.
For further details, please refer to the documentation of each proc-macro.

## 4. Derive macros to implement `Deserialize` and `Serialize`

Expand Down
Loading

0 comments on commit 011c778

Please sign in to comment.