Skip to content

Commit

Permalink
Fix clippy links (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb authored Feb 3, 2025
2 parents 9f8f607 + 4ad60a2 commit ec57d5e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 60 deletions.
8 changes: 4 additions & 4 deletions serde_with/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
//! Some common use cases are:
//!
//! * De/Serializing a type using the `Display` and `FromStr` traits, e.g., for `u8`, `url::Url`, or `mime::Mime`.
//! Check [`DisplayFromStr`] for details.
//! Check [`DisplayFromStr`] for details.
//! * Support for arrays larger than 32 elements or using const generics.
//! With `serde_as` large arrays are supported, even if they are nested in other types.
//! `[bool; 64]`, `Option<[u8; M]>`, and `Box<[[u8; 64]; N]>` are all supported, as [this examples shows](#large-and-const-generic-arrays).
//! With `serde_as` large arrays are supported, even if they are nested in other types.
//! `[bool; 64]`, `Option<[u8; M]>`, and `Box<[[u8; 64]; N]>` are all supported, as [this examples shows](#large-and-const-generic-arrays).
//! * Skip serializing all empty `Option` types with [`#[skip_serializing_none]`][skip_serializing_none].
//! * Apply a prefix / suffix to each field name of a struct, without changing the de/serialize implementations of the struct using [`with_prefix!`][] / [`with_suffix!`][].
//! * Deserialize a comma separated list like `#hash,#tags,#are,#great` into a `Vec<String>`.
//! Check the documentation for [`serde_with::StringWithSeparator::<CommaSeparator, T>`][StringWithSeparator].
//! Check the documentation for [`serde_with::StringWithSeparator::<CommaSeparator, T>`][StringWithSeparator].
//!
//! ## Getting Help
//!
Expand Down
2 changes: 1 addition & 1 deletion serde_with/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ pub mod maps_first_key_wins {
///
/// 1. It is useful for instance to create an enum with a catch-all variant that will accept any incoming data.
/// 2. [`untagged`] enum representations do not allow the `other` annotation as the fallback enum variant.
/// With this function you can emulate an `other` variant, which can deserialize any data carrying enum.
/// With this function you can emulate an `other` variant, which can deserialize any data carrying enum.
///
/// **Note:** Using this function will prevent deserializing data-less enum variants.
/// If this is a problem depends on the data format.
Expand Down
6 changes: 3 additions & 3 deletions serde_with/src/serde_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
/// The macro takes four arguments:
///
/// 1. The name of the converter type.
/// The type can be prefixed with a visibility modifies like `pub` or `pub(crate)`.
/// By default, the type is not marked as public (`pub(self)`).
/// The type can be prefixed with a visibility modifies like `pub` or `pub(crate)`.
/// By default, the type is not marked as public (`pub(self)`).
/// 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
///
Expand Down
95 changes: 43 additions & 52 deletions serde_with_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ where
.iter_mut()
.map(|field| function(field).map_err(|err| err.with_span(&field)))
// turn the Err variant into the Some, such that we only collect errors
.filter_map(|res| match res {
Err(e) => Some(e),
Ok(()) => None,
})
.filter_map(std::result::Result::err)
.collect();
if errors.is_empty() {
Ok(())
Expand All @@ -147,10 +144,7 @@ where
.iter_mut()
.map(|field| function(field).map_err(|err| err.with_span(&field)))
// turn the Err variant into the Some, such that we only collect errors
.filter_map(|res| match res {
Err(e) => Some(e),
Ok(()) => None,
})
.filter_map(std::result::Result::err)
.collect();
if errors.is_empty() {
Ok(())
Expand Down Expand Up @@ -199,10 +193,7 @@ where
.iter_mut()
.map(|variant| apply_on_fields(&mut variant.fields, function))
// turn the Err variant into the Some, such that we only collect errors
.filter_map(|res| match res {
Err(e) => Some(e),
Ok(()) => None,
}),
.filter_map(std::result::Result::err),
);

if errors.is_empty() {
Expand Down Expand Up @@ -517,53 +508,53 @@ 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 type's `Serialize` implementation
/// should be used. 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.
/// The placeholder type `_` marks all the places where the type's `Serialize` implementation
/// should be used. 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 now have something like `::serde_with::As::<Vec<::serde_with::Same>>`.
/// The `As` type acts as the opposite of the `Same` type.
/// It allows using a `SerializeAs` type whenever a `Serialize` is required.
/// In the above example we now have something like `::serde_with::As::<Vec<::serde_with::Same>>`.
/// The `As` type acts as the opposite of the `Same` type.
/// It allows using a `SerializeAs` type whenever a `Serialize` is required.
///
/// 3. Translate the `*as` attributes into the serde equivalent ones.
/// `#[serde_as(as = ...)]` will become `#[serde(with = ...)]`.
/// Similarly, `serialize_as` is translated to `serialize_with`.
/// `#[serde_as(as = ...)]` will become `#[serde(with = ...)]`.
/// Similarly, `serialize_as` is translated to `serialize_with`.
///
/// The field attributes will be kept on the struct/enum such that other macros can use them
/// too.
/// The field attributes will be kept on the struct/enum such that other macros can use them
/// too.
///
/// 4. It searches `#[serde_as(as = ...)]` if there is a type named `BorrowCow` under any path.
/// If `BorrowCow` is found, the attribute `#[serde(borrow)]` is added to the field.
/// If `#[serde(borrow)]` or `#[serde(borrow = "...")]` is already present, this step will be
/// skipped.
/// If `BorrowCow` is found, the attribute `#[serde(borrow)]` is added to the field.
/// If `#[serde(borrow)]` or `#[serde(borrow = "...")]` is already present, this step will be
/// skipped.
///
/// 5. Restore the ability of accepting missing fields if both the field and the transformation are `Option`.
///
/// An `Option` is detected by an exact text match.
/// Renaming an import or type aliases can cause confusion here.
/// The following variants are supported.
/// * `Option`
/// * `std::option::Option`, with or without leading `::`
/// * `core::option::Option`, with or without leading `::`
/// An `Option` is detected by an exact text match.
/// Renaming an import or type aliases can cause confusion here.
/// The following variants are supported.
/// * `Option`
/// * `std::option::Option`, with or without leading `::`
/// * `core::option::Option`, with or without leading `::`
///
/// If the field is of type `Option<T>` and the attribute `#[serde_as(as = "Option<S>")]` (also
/// `deserialize_as`; for any `T`/`S`) then `#[serde(default)]` is applied to the field.
/// If the field is of type `Option<T>` and the attribute `#[serde_as(as = "Option<S>")]` (also
/// `deserialize_as`; for any `T`/`S`) then `#[serde(default)]` is applied to the field.
///
/// This restores the ability of accepting missing fields, which otherwise often leads to confusing [serde_with#185](https://github.com/jonasbb/serde_with/issues/185).
/// `#[serde(default)]` is not applied, if it already exists.
/// It only triggers if both field and transformation are `Option`s.
/// For example, using `#[serde_as(as = "NoneAsEmptyString")]` on `Option<String>` will not see
/// any change.
/// This restores the ability of accepting missing fields, which otherwise often leads to confusing [serde_with#185](https://github.com/jonasbb/serde_with/issues/185).
/// `#[serde(default)]` is not applied, if it already exists.
/// It only triggers if both field and transformation are `Option`s.
/// 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 suppressed by adding
/// `#[serde_as(no_default)]`.
/// 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)]`.
/// This can be combined like `#[serde_as(as = "Option<S>", no_default)]`.
///
/// After all these steps, the code snippet will have transformed into roughly this.
///
Expand Down Expand Up @@ -1017,11 +1008,11 @@ fn has_type_embedded(type_: &Type, embedded_type: &syn::Ident) -> bool {
/// or enum. Currently, these arguments to the attribute are possible:
///
/// * **`#[serde_with(crate = "...")]`**: This allows using `DeserializeFromStr` when `serde_with`
/// is not available from the crate root. This happens while [renaming dependencies in
/// Cargo.toml][cargo-toml-rename] or when re-exporting the macro from a different crate.
/// is not available from the crate root. This happens while [renaming dependencies in
/// Cargo.toml][cargo-toml-rename] or when re-exporting the macro from a different crate.
///
/// This argument is analogue to [serde's crate argument][serde-crate] and the [crate argument
/// to `serde_as`][serde-as-crate].
/// This argument is analogue to [serde's crate argument][serde-crate] and the [crate argument
/// to `serde_as`][serde-as-crate].
///
/// # Example
///
Expand Down Expand Up @@ -1151,11 +1142,11 @@ fn deserialize_fromstr(mut input: DeriveInput, serde_with_crate_path: Path) -> T
/// or enum. Currently, these arguments to the attribute are possible:
///
/// * **`#[serde_with(crate = "...")]`**: This allows using `SerializeDisplay` when `serde_with` is
/// not available from the crate root. This happens while [renaming dependencies in
/// Cargo.toml][cargo-toml-rename] or when re-exporting the macro from a different crate.
/// not available from the crate root. This happens while [renaming dependencies in
/// Cargo.toml][cargo-toml-rename] or when re-exporting the macro from a different crate.
///
/// This argument is analogue to [serde's crate argument][serde-crate] and the [crate argument
/// to `serde_as`][serde-as-crate].
/// This argument is analogue to [serde's crate argument][serde-crate] and the [crate argument
/// to `serde_as`][serde-as-crate].
///
/// # Example
///
Expand Down

0 comments on commit ec57d5e

Please # to comment.