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

Namespace pollution prevent some usage #43

Open
Menduist opened this issue Jul 13, 2022 · 2 comments
Open

Namespace pollution prevent some usage #43

Menduist opened this issue Jul 13, 2022 · 2 comments

Comments

@Menduist
Copy link
Contributor

Menduist commented Jul 13, 2022

Example:

import
  serialization, json_serialization,
  stew/base64

echo Base64.encode(@[50.byte])

Doesn't compile

Switching to

echo base64.encode(Base64, @[50.byte])

Make it work, but in my case, this line is in a generic procedure in a dependency, so I can't change it
Instead, I had to use

from serialization import nil
from json_serialization import Reader, init, readValue, handleReadException
import json_serialization/std/options
@jangko
Copy link
Contributor

jangko commented Jul 14, 2022

The solution to this issue is we can use setReader and setWriter to generate a set of specialized encode, decode, loadFile, saveFile and friends.

Rather than using a too generic Format: type, the generated specialized procs can use something like Format: Json thus preventing the above issue.

Furthermore we can adjust setReader and setWriter to actually produce this set of standard operation or not. Because for example in toml-serialization, I ended up overriding all of these encoders/decoders.

@jangko
Copy link
Contributor

jangko commented Jan 18, 2024

This is the explanation from nim manual nim-lang/Nim#23217.

I think we cannot put our hope too much to the compiler. Should find our own workaround.

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