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

Optional ints and floats #1053

Closed
FedorLap2006 opened this issue Dec 11, 2021 · 2 comments
Closed

Optional ints and floats #1053

FedorLap2006 opened this issue Dec 11, 2021 · 2 comments

Comments

@FedorLap2006
Copy link
Collaborator

Right now we need a better way of handling min max constraints and their zero values.
As @iopred and @CarsonHoffman suggested, we should use *int and *float64, but I think I've found a better way of doing that.
While still holding on to the idea of using pointers we can create utility functions (which will be also useful in #1026 and #1052) for constructing an optional int and an optional float. They would look something like that:

func NewOptionalInt(v int) *int {
     return &v
}

What do you think?

@danbrakeley
Copy link
Contributor

danbrakeley commented Dec 16, 2021

This a lot of precedence for this, for example here's what the AWS Go SDK uses: https://github.com/aws/smithy-go/blob/main/ptr/to_ptr.go

You could probably shorten the name from NewOptionalInt to just Int as well, or put it in a package called ptr like the AWS example, so the user can type something short and simple, like ptr.Int(n) (compare this to discordgo.NewOptionalInt(n)).

@FedorLap2006
Copy link
Collaborator Author

I mean yeah, but we shouldn't embed everything in discordgo, it was just a utility function, but making a package, I don't really know. Probably would be better just to leave it as it is, being a pointer, and remove the functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants