Skip to content

Commit

Permalink
Derive Eq and Hash wherever possible
Browse files Browse the repository at this point in the history
In server SDKs, these traits can be implemented by any shape _except_ if
the shape's closure contains:

1. A `float`, `double`, or `document` shape: floating point types in
   Rust do not implement `Eq`. Similarly, [`document` shapes] may
   contain arbitrary JSON-like data containing floating point values.
2. A [@streaming] shape: all the streaming data would need to be
   buffered first to compare it.

Additionally, the `Hash` trait cannot be implemented by shapes whose
closure contains:

1. A `map` shape: we render `map` shapes as `std::collections::HashMap`,
   which _do not_ implement `Hash`. See
   smithy-lang/smithy#1567.

In **client SDKs, these traits cannot be derived on any code-generated
Rust types corresponding to Smithy shapes**, since e.g. adding new
optional members to a structure [is a backwards-compatible change], and
doing so alters the semantics of these traits.

However, this commit does implement these traits for the
`aws_smithy_types::date_time::DateTime` and `aws_smithy_types::Blob`
runtime types.

This change is necessary to efficiently implement the `@uniqueItems`
constraint trait in server SDKs.

This commit also introduces a constrained shape symbol metadata provider
(`ConstrainedShapeSymbolMetadataProvider.kt`), to centralize generation
of Rust metadata (derives, visibility) in one place, instead of each
constrained type generator having to manually adjust metadata. Some
constrained type methods are now conditionally generated based on
visibility, instead of relying on `#[allow(dead_code)]`.

[`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
[`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html
[`document` shapes]: https://smithy.io/2.0/spec/simple-types.html#document
[@streaming]: https://smithy.io/2.0/spec/streaming.html
[is a backwards-compatible change]: https://smithy.io/2.0/guides/evolving-models.html#updating-structures
  • Loading branch information
david-perez committed Jan 18, 2023
1 parent fa929a6 commit d926b14
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit d926b14

Please sign in to comment.