discord.v icon indicating copy to clipboard operation
discord.v copied to clipboard

Optional fields rewrite

Open Terisback opened this issue 3 years ago • 1 comments

At the moment, optional fields in structures are not implemented in vlang, but as far as I understand this is a matter of time. We can try to implement our own through generics:

struct None {}
type OptError = string | None
struct Opt<T> {
    value T
    error OptError = None{}
}

struct MessageModify {
    text Opt<string>
}

editQuery := MessageModify{Opt<string>{value: 'Hello there!'})
// Then in rest method check every field error and serialize

Options will replace almost all fields in already written structures

or do nothing yet and wait for implementation in language

Terisback avatar Jan 11 '21 17:01 Terisback

Now we are just waiting for the implementation of optional fields in structures

Terisback avatar Jan 16 '21 10:01 Terisback