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

Support map keys that implement TextMarshaler and TextUnmarshaler #181

Closed
expectation1009 opened this issue Jun 17, 2017 · 4 comments
Closed

Comments

@expectation1009
Copy link

expectation1009 commented Jun 17, 2017

type Config struct {
	FileName   string
	FileNameCn string
	Cols       map[int]Column
}

config like top, when decode will have a error "work faild reflect: call of reflect.Value.SetString on int Value"
if change Cols define to "map[string]Column" it works

@cespare
Copy link
Collaborator

cespare commented Aug 10, 2017

I don't think I would expect this to work, since TOML doesn't have a way of expressing int keys. The error message is not great, though.

@shousper
Copy link

@cespare I have a similar issue with a type Blah int32 from a protobuf enum. I implemented TextMarshaler and TextUnmarshaler but am still unable to use these as a key for a map.

Could this possibly be supported? The configuration would only support the string values, obviously, per the TOML spec.

@arp242
Copy link
Collaborator

arp242 commented Jun 9, 2021

Only map[string]... is supported right now, as TOML only supports strings as map keys. I clarified the error message on that in a PR earlier today.

Supporting map keys which support TextUnmarshaler and TextMarshaler would be an option worth investigating; I can't think of any downsides off-hand. I'll rename the issue to this.

@arp242 arp242 changed the title if map's key is int will decode fail Support map keys that implement TextMarshaler and TextUnmarshaler Jun 9, 2021
arp242 added a commit that referenced this issue Jun 25, 2022
@arp242
Copy link
Collaborator

arp242 commented Oct 1, 2023

I'm closing this for now as it's not super-clear to me what the practical real-world use case for this is, it's some amount of work to implement, and it doesn't seem to come up that often. If you still want this, then please let me know the use case, so we can see what the best solution is (which may be using TextMarshaler or something else).

@arp242 arp242 closed this as completed Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants