Skip to content

feat(model): add enum variant from/tryfrom conversion#2502

Merged
vilgotf merged 4 commits intomainfrom
vilgotf/enum-conversion
Feb 21, 2026
Merged

feat(model): add enum variant from/tryfrom conversion#2502
vilgotf merged 4 commits intomainfrom
vilgotf/enum-conversion

Conversation

@vilgotf
Copy link
Member

@vilgotf vilgotf commented Dec 31, 2025

These convenience implementations bring a better developer experience. This PR also features some cleanup with struct field/enum variant sorting

@github-actions github-actions bot added c-model Affects the model crate c-util Affects the util crate t-feature Addition of a new feature labels Dec 31, 2025
User(Id<UserMarker>),
}

impl CommandOptionValue {
Copy link
Member Author

Choose a reason for hiding this comment

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

SubCommand and SubCommandGroup have the same inner type, so no conversion implementations are provided

///
/// [`member`]: Self::member
/// [`user`]: Self::user
pub fn into_author(self) -> Option<User> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Matching owned variant to author()

@@ -326,37 +469,37 @@ impl<'de> Deserialize<'de> for Component {
#[derive(Debug, Deserialize)]
#[serde(field_identifier, rename_all = "snake_case")]
enum Field {
Copy link
Member Author

Choose a reason for hiding this comment

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

Did not bother sorting its usage

command::{
Command, CommandOption, CommandOptionChoice, CommandOptionChoiceValue,
CommandOptionType, CommandOptionValue, CommandType,
CommandOptionType, CommandType,
Copy link
Member Author

Choose a reason for hiding this comment

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

Applied the provided From implementations

@vilgotf vilgotf added c-model Affects the model crate c-util Affects the util crate labels Dec 31, 2025
Copy link
Member

@Erk- Erk- left a comment

Choose a reason for hiding this comment

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

Looks good, I hope its not too painful to rebase on top of.

@vilgotf vilgotf merged commit 0f7167b into main Feb 21, 2026
9 checks passed
@vilgotf vilgotf deleted the vilgotf/enum-conversion branch February 21, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c-model Affects the model crate c-util Affects the util crate t-feature Addition of a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants