-
Notifications
You must be signed in to change notification settings - Fork 13
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
@safety problems with JSONToken #5
Comments
Do you mean in case assertions are disabled? |
Well, I don't think it's a good choice here though, as it precludes string safeString(JSONToken token) @trusted
{
return token.kind == JSONToken.Kind.string? token.string : null;
} I think a better design is for the accessor properties to validate the input with JSONToken token;
auto str = token.get!string("default");
assert(str == "default"); Either way I think What do you think? |
I guess it depends on how much
I don't think that this is a good idea, but that's a different topic. What I used to do in C++ was to write a safe fallback path after an assertion, so that the release build would degrade gracefully:
The same could be applied here, too, to make the method a valid
Of course, converting the I'm not sure about using exceptions. Adding two ways to access the values complicates the interface, but of course it also has its merit. Maybe this would be a good point to raise in a wider community review discussion. |
Fix destruction Deprecate `empty` in favour of `cast(bool)` Make initialization a precondition of `get` for non-class types
JSONToken.string does not present a memory safe interface, as it may return a dangling reference if the token's
kind
is not a string.The text was updated successfully, but these errors were encountered: