Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(model/id)!: add const id creation api #1402

Merged
merged 15 commits into from
Dec 31, 2021
Merged

feat(model/id)!: add const id creation api #1402

merged 15 commits into from
Dec 31, 2021

Conversation

zeylahellyer
Copy link
Member

@zeylahellyer zeylahellyer commented Dec 30, 2021

Rename Id::new to Id::new_checked and add a new const method named new that takes a value and creates a non-zero ID, panicking if the value is 0. This is useful when you have a hardcoded value, such as in tests or in const contexts.

Code such as:

let guild_id = Id::new(1).expect("non zero id");

can now become:

let guild_id = Id::new(1);

// or
const GUILD_ID: Id<GuildMarker> = Id::new(1);

BREAKING CHANGES: increases our MSRV to Rust 1.57.

Add a const method to IDs named `new_checked` that takes a value and
creates a non-zero ID, panicking if the value is 0. This is useful when
you have a hardcoded value, such as in tests or in const contexts.

Code such as:
```
let guild_id = GuildId::new(1).expect("non zero id");
```

can now become:

```
let guild_id = GuildId::new_checked(1);

// or
const GUILD_ID: GuildId = GuildId::new_checked(1);
```

Signed-off-by: Zeyla Hellyer <[email protected]>
Signed-off-by: Zeyla Hellyer <[email protected]>
@zeylahellyer zeylahellyer added c-model Affects the model crate m-breaking change Breaks the public API. t-feature Addition of a new feature labels Dec 30, 2021
Signed-off-by: Zeyla Hellyer <[email protected]>
model/src/id/mod.rs Outdated Show resolved Hide resolved
Signed-off-by: Zeyla Hellyer <[email protected]>
@zeylahellyer zeylahellyer changed the title feat(model/id)!: add 'new_checked' api feat(model/id)!: add const id creation api Dec 30, 2021
Signed-off-by: Zeyla Hellyer <[email protected]>
@zeylahellyer zeylahellyer marked this pull request as draft December 30, 2021 20:14
Signed-off-by: Zeyla Hellyer <[email protected]>
Signed-off-by: Zeyla Hellyer <[email protected]>
Signed-off-by: Zeyla Hellyer <[email protected]>
Signed-off-by: Zeyla Hellyer <[email protected]>
Signed-off-by: Zeyla Hellyer <[email protected]>
@zeylahellyer zeylahellyer marked this pull request as ready for review December 30, 2021 21:15
@zeylahellyer
Copy link
Member Author

I did #1403's changes here. I would have either had to rename everything from new to new_checked to make it compile, or just make everything use the new new here, so I just opted for the latter to keep it simple.

Copy link
Member

@vilgotf vilgotf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add rust-version = "1.57" to all packages's Cargo.toml as described here

model/src/id/mod.rs Outdated Show resolved Hide resolved
examples/lavalink-basic-bot/src/main.rs Outdated Show resolved Hide resolved
zeylahellyer and others added 2 commits December 30, 2021 17:36
@zeylahellyer
Copy link
Member Author

Let's also add rust-version = "1.57" to all packages's Cargo.toml as described here

I'd prefer to do this in a dedicated PR

7596ff
7596ff previously requested changes Dec 31, 2021
examples/lavalink-basic-bot/src/main.rs Show resolved Hide resolved
Signed-off-by: Zeyla Hellyer <[email protected]>
@zeylahellyer zeylahellyer added this to the Model Rework milestone Dec 31, 2021
@zeylahellyer zeylahellyer self-assigned this Dec 31, 2021
@github-actions github-actions bot added c-all Affects all crates or the project as a whole c-cache Affects the cache crate c-command-parser c-gateway Affects the gateway crate c-http Affects the http crate c-lavalink Affects the lavalink crate c-standby Affects the standby crate c-util Affects the util crate c-validate Affects the validate crate t-ci Anything to do with CI. labels Dec 31, 2021
@zeylahellyer zeylahellyer merged commit 1aa6364 into twilight-rs:next Dec 31, 2021
@zeylahellyer zeylahellyer deleted the feat-model-id-new-checked branch December 31, 2021 19:23
7596ff added a commit that referenced this pull request Jan 23, 2022
Changes

All types and method signatures have been updated to use the new `Id<T>` syntax
([#1260] - [@zeylahellyer]).

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

Methods that return an image hash, such as `CachedGuild::banner`, now return an
`ImageHash` instead of a string ([#1405] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

`UpdateCache` trait is now sealed ([#1431] - [@vilgotf]).

[#1260]: #1260
[#1402]: #1402
[#1405]: #1405
[#1412]: #1412
[#1431]: #1431

[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
Changes

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

[#1402]: #1402
[#1412]: #1412

[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
Changes

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

[#1402]: #1402
[#1412]: #1412

[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
Changes

The `rustls` feature has been removed ([#1314] - [@Gelbpunkt]). Users
must manually select one of `rustls-native-roots` or
`rustls-webpki-roots`.

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

[#1314]: #1314
[#1402]: #1402
[#1412]: #1412

[@Gelbpunkt]: https://github.com/Gelbpunkt
[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
Additions

Add `Information::{ratelimit_refill, ratelimit_requests}` to view how
much time until the shard ratelimiter resets and how many requests until
the next refill ([#1368] - [@itohatweb])

Add `ClusterBuilder::shard_presence`, which allows setting a custom
presence based on a shard's ID ([#1474] - [@7596ff]).

Changes

The `rustls` feature has been removed ([#1314] - [@Gelbpunkt]). Users
must manually select one of `rustls-native-roots` or
`rustls-webpki-roots`.

`{CommandErrorType, SendErrorType}::ExecutorShutDown` have been removed,
since they are no longer possible ([#1368] - [@itohatweb]).

No longer derive `Deserialize` and `Serialize` on `Information` ([#1368]
- [@itohatweb]).

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

Constructors that used to take `impl Into<String>` now simply accept a
`String` ([#1481] - [@vilgotf]).

[#1314]: #1314
[#1368]: #1368
[#1402]: #1402
[#1412]: #1412
[#1474]: #1474
[#1481]: #1481

[@7596ff]: https://github.com/7596ff
[@itohatweb]: https://github.com/itohatweb
[@Gelbpunkt]: https://github.com/Gelbpunkt
[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
Additions

Add `Path` variants for scheduled events ([#1347] - [@7596ff]).

Changes

`Method::into_http` has been renamed to `to_http` ([#1398] -
[@vilgotf]).

`Path` variants that contained a `Box<str>` now contain a `String`
([#1398] - [@vilgotf]).

`Present::into_bucket` now returns a `String` ([#1398] - [@vilgotf]).

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

[#1347]: #1347
[#1398]: #1398
[#1402]: #1402
[#1412]: #1412

[@7596ff]: https://github.com/7596ff
[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
Validation

Validation has been moved to a new crate, `twilight_validate` ([#1331] -
[@7596ff]). Similar concerns such as creating messages
(`MessageValidationError`) or editing channels (`ChannelValidationError`) have
been grouped together in error types, and these error types replace the custom
error types associated with each request builder. Miscellaneous validation
functions that were associated things like get user limits are also placed under
one error type, `ValidationError`.

The following error types are now returned by the following methods:
- `ChannelValidationError`
  - `Client::create_guild_channel`
  - `Client::create_thread_from_message`
  - `Client::create_thread`
  - `CreateGuildChannel::rate_limit_per_user`
  - `CreateGuildChannel::topic`
  - `UpdateChannel::name`
  - `UpdateChannel::rate_limit_per_user`
  - `UpdateChannel::topic`
  - `UpdateThread::name`
  - `UpdateThread::rate_limit_per_user`
- `CommandValidationError`
  - `InteractionClient::set_command_permissions`
  - `InteractionClient::update_command_permissions`
- `MessageValidationError`
  - `CreateFollowupMessage::components`
  - `CreateMessage::components`
  - `CreateMessage::content`
  - `CreateMessage::embeds`
  - `CreateMessage::stickers`
  - `CreateWebhookMessage::components`
  - `UpdateFollowupMessage::components`
  - `UpdateFollowupMessage::content`
  - `UpdateFollowupMessage::embeds`
  - `UpdateMessage::components`
  - `UpdateMessage::content`
  - `UpdateMessage::embeds`
  - `UpdateOriginalResponse::components`
  - `UpdateOriginalResponse::content`
  - `UpdateOriginalResponse::embeds`
  - `UpdateWebhookMessage::components`
  - `UpdateWebhookMessage::content`
  - `UpdateWebhookMessage::embeds`
- `ValidationError`
  - `AddGuildMember::nick`
  - `Client::create_guild_from_template`
  - `Client::create_stage_instance`
  - `Client::create_template`
  - `CreateBan::delete_message_days`
  - `CreateGuildPrune::days`
  - `CreateInvite::max_uses`
  - `CreateTemplate::description`
  - `GetChannelMessages::limit`
  - `GetCurrentUserGuilds::limit`
  - `GetGuildAuditLog::limit`
  - `GetGuildMembers::limit`
  - `GetGuildPruneCount::limit`
  - `GetReactions::limit`
  - `SearchGuildMembers::limit`
  - `UpdateCurrentMember::nick`
  - `UpdateCurrentUser::username`
  - `UpdateGuild::name`
  - `UpdateGuildMember::communication_disabled_until`
  - `UpdateGuildMember::nick`
  - `UpdateStageInstance::topic`
  - `UpdateTemplate::description`
  - `UpdateTemplate::name`

The following functions now perform validation:
- `MessageValidationError`
  - `CreateFollowupMessage::content`
  - `CreateFollowupMessage::embeds`
  - `CreateWebhookMessage::content`
  - `CreateWebhookMessage::embeds`

Additions

Add a sealed trait located at `request::TryIntoRequest` for converting a
typed request builder into a raw `request::Request` ([#1162] -
[@zeylahellyer]). This allows users to inspect requests prior to sending
them which may be useful for debugging and unit testing.

Support guild scheduled events ([#1347] - [@7596ff]). Adds the following
methods: `Client::create_guild_scheduled_event`,
`Client::delete_guild_scheduled_event`,
`Client::guild_scheduled_event_users`, `Client::guild_scheduled_event`,
`Client::guild_scheduled_events`,
`Client::update_guild_scheduled_event`.

Changes

All types and method signatures have been updated to use the new `Id<T>`
syntax ([#1260] - [@zeylahellyer]).

Requests requiring an `Id<ApplicationMarker>` are now created through an
`InteractionClient` ([#1275] - [@zeylahellyer]]). This is created by
passing the ID to `Client::interaction`. It replaces
`set_application_id`. The interaction methods are no longer on `Client`.

The `rustls` feature has been removed ([#1314] - [@Gelbpunkt]). Users
must manually select one of `rustls-native-roots` or
`rustls-webpki-roots`.

The `ErrorCode` which contained custom names and descriptions for each
API error code has been removed ([#1394] - [@zeylahellyer]). Users can
now read `GeneralApiError::code: u64` to see the code.

`InteractionClient::{create_global_command, create_guild_command}` no
longer accept a `name` when first creating the request ([#1395] -
[@baptiste0928]).  Instead, depending on the type of command the user is
created, different validation is performed. For `ChatInput` commands,
validation ensures that the name is between 1 and 32 characters in
length and that it contains no uppercase letters. For `Message` and
`User` commands, validation only ensures the length is correct. Similar
validation is performed on `ChatInput` `option`s.

`Route` now directly implements `Display` ([#1397] - [@vilgotf]).

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

`RequestReactionType` now directly implements `Display` ([#1457] -
[@vilgotf]).

[#1162]: #1162
[#1260]: #1260
[#1275]: #1275
[#1314]: #1314
[#1331]: #1331
[#1394]: #1394
[#1395]: #1395
[#1402]: #1402
[#1412]: #1412
[#1457]: #1457

[@7596ff]: https://github.com/7596ff
[@baptiste0928]: https://github.com/baptiste0928
[@Gelbpunkt]: https://github.com/Gelbpunkt
[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
All types and method signatures have been updated to use the new `Id<T>`
syntax ([#1260] - [@zeylahellyer]).

Support lavalink 3.4 ([#1292] - [@james7132]). `PlayerUpdateState` now
contains a `connected` field, and its `position` field is now
`Option`al.

The `rustls` feature has been removed ([#1314] - [@Gelbpunkt]). Users
must manually select one of `rustls-native-roots` or
`rustls-webpki-roots`.

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

[#1260]: #1260
[#1292]: #1292
[#1314]: #1314
[#1402]: #1402
[#1412]: #1412

[@Gelbpunkt]: https://github.com/Gelbpunkt
[@james7132]: https://github.com/james7132
[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
Changes

All types and method signatures have been updated to use the new `Id<T>`
syntax ([#1260] - [@zeylahellyer]).

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

[#1260]: #1260
[#1402]: #1402
[#1412]: #1412

[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
`Id<T>`

IDs are now a unified type (`Id`) with marker generics
(`ApplicationMarker`, ...) ([#1260] - [@zeylahellyer]). The new type
implements all of what each type used to implement, as well as
`FromStr`, `TryFrom<u64>`, and `TryFrom<i64>`, and others. `Id::cast`
aids in converting between IDs without copying. See the PR and the
documentation for more details.

Additions

Support scheduled events ([#1347] - [@7596ff]). Adds the following
types: `EntityMetadata`, `EntityType`, `GuildScheduledEventUser`,
`GuildScheduledEvent`, `PrivacyLevel`, and `Status`.

Changes

All types and method signatures have been updated to use the new `Id<T>`
syntax ([#1260] - [@zeylahellyer]).

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

Image hashes are now parsed and stored in a more efficient struct,
rather than deserializing as a `String` ([#1405] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

`StageInstance::discoverable_disabled` and `PrivacyLevel::Public` have
been removed, as public stage instances are no longer supported ([#1479]
- [@itohatweb]).

`GuildWidget::channel_id` is now optional ([#1480] - [@itohatweb]).

[#1260]: #1260
[#1402]: #1402
[#1405]: #1405
[#1412]: #1412
[#1479]: #1479
[#1480]: #1480

[@7596ff]: https://github.com/7596ff
[@itohatweb]: https://github.com/itohatweb
[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
Changes

All types and method signatures have been updated to use the new `Id<T>`
syntax ([#1260] - [@zeylahellyer]).

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

Fixes

Missing ID marker implementations have been added ([#1471] -
[@zeylahellyer]).

[#1260]: #1260
[#1402]: #1402
[#1412]: #1412
[#1471]: #1471

[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jan 23, 2022
Changes

All types and method signatures have been updated to use the new `Id<T>`
syntax ([#1260] - [@zeylahellyer]).

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

[#1260]: #1260
[#1402]: #1402
[#1412]: #1412

[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
zeylahellyer pushed a commit to twilight-rs/command-parser that referenced this pull request Apr 15, 2022
Changes

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

[#1402]: twilight-rs/twilight#1402
[#1412]: twilight-rs/twilight#1412

[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
zeylahellyer pushed a commit to twilight-rs/embed-builder that referenced this pull request Jun 5, 2022
Changes

The MSRV has been updated to 1.57 ([#1402] - [@zeylahellyer]).

The Rust edition has been updated to 2021 ([#1412] - [@vilgotf]).

[#1402]: twilight-rs/twilight#1402
[#1412]: twilight-rs/twilight#1412

[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-all Affects all crates or the project as a whole c-cache Affects the cache crate c-gateway Affects the gateway crate c-http Affects the http crate c-lavalink Affects the lavalink crate c-model Affects the model crate c-standby Affects the standby crate c-util Affects the util crate c-validate Affects the validate crate m-breaking change Breaks the public API. t-ci Anything to do with CI. t-feature Addition of a new feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants