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

Implement FromStr for ids #2504

Merged
merged 1 commit into from
Aug 20, 2023
Merged

Implement FromStr for ids #2504

merged 1 commit into from
Aug 20, 2023

Conversation

onlycs
Copy link
Contributor

@onlycs onlycs commented Aug 9, 2023

Useful for databasing, i.e. in Postgres, where ID's must be stored as strings because u64::MAX is larger than the largest BigInt type.

// before
Id::from(some_string.parse::<u64>().unwrap());

// after
Id::from_str(&some_string).unwrap();

@github-actions github-actions bot added the model Related to the `model` module. label Aug 9, 2023
@arqunis arqunis added the enhancement An improvement to Serenity. label Aug 9, 2023
@tazz4843
Copy link
Contributor

Unrelated to this PR, but for Postgres, you can simply cast to a i64 and it'll be fine even once the 64th bit is used as long as you cast back as well.

@scottbot95
Copy link

you can simply cast to a i64 and it'll be fine even once the 64th bit is used as long as you cast back as well.

And here I was foolishly using std::mem::transmute to "re-interpret" the u64 as an i64 cuz I just assumed the cast would fail or otherwise behave in an undesirable way....

@arqunis arqunis merged commit 8b2ae0e into serenity-rs:current Aug 20, 2023
6 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement to Serenity. model Related to the `model` module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants