Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

add method to extract values from modals #24

Open
laralove143 opened this issue Jun 29, 2023 · 0 comments
Open

add method to extract values from modals #24

laralove143 opened this issue Jun 29, 2023 · 0 comments

Comments

@laralove143
Copy link
Owner

while it's rather simple it ends up being a bit of boilerplate when extracting multiple components' values, im not sure if theres a need for this for other components, since always have a single value

it should be a trait on ModalInteractionData that simply takes a custom_id and returns an option, this has the limitation of returning a reference so that it doesnt consume it (since it probably has more components)

the trickier bit is consuming the data and returning a [String] so that it can be destructed, it could be collected to a HashMap or struct but former is overhead and latter requires proc macros and for the user to create a struct

this can be done using const generics

fn values<const N: usize>(self, custom_ids: [&str; N]) -> [String; N];

although this requires that the users provide the custom_ids statically, it can be used like

let [val1, val2] = data.values(["val1", "val2"])?; // returns error if not enough values
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant