[PATCH 1/7] go: Use iota in enum bindings

Austin Clements amdragon at MIT.EDU
Wed Jul 18 13:17:48 PDT 2012


Hah.  I guess nobody has tried to modify a notmuch database using the
Go bindings.

Could this instead assign the constants to
C.NOTMUCH_DATABASE_MODE_READ_ONLY, etc, rather than duplicating their
values?  It would be nice to do that for the Status values as well
(which are correctly using iota, at least).

Quoth Adrien Bustany on Jul 18 at  9:34 pm:
> Using iota is the correct way to get the values in the enum increment
> automatically. The old code would just set all the enum values to 0.
> ---
>  bindings/go/src/notmuch/notmuch.go |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/bindings/go/src/notmuch/notmuch.go b/bindings/go/src/notmuch/notmuch.go
> index 00bd53a..ecd7418 100644
> --- a/bindings/go/src/notmuch/notmuch.go
> +++ b/bindings/go/src/notmuch/notmuch.go
> @@ -86,7 +86,7 @@ type Filenames struct {
>  type DatabaseMode C.notmuch_database_mode_t
>  
>  const (
> -	DATABASE_MODE_READ_ONLY DatabaseMode = 0
> +	DATABASE_MODE_READ_ONLY DatabaseMode = iota
>  	DATABASE_MODE_READ_WRITE
>  )
>  
> @@ -386,7 +386,7 @@ func (self *Database) CreateQuery(query string) *Query {
>  type Sort C.notmuch_sort_t
>  
>  const (
> -	SORT_OLDEST_FIRST Sort = 0
> +	SORT_OLDEST_FIRST Sort = iota
>  	SORT_NEWEST_FIRST
>  	SORT_MESSAGE_ID
>  	SORT_UNSORTED
> @@ -774,7 +774,7 @@ func (self *Message) GetFileName() string {
>  type Flag C.notmuch_message_flag_t
>  
>  const (
> -	MESSAGE_FLAG_MATCH Flag = 0
> +	MESSAGE_FLAG_MATCH Flag = iota
>  )
>  
>  /* Get a value of a flag for the email corresponding to 'message'. */


More information about the notmuch mailing list