json_in_type icon indicating copy to clipboard operation
json_in_type copied to clipboard

Unnecessary "use json_in_type::*"

Open ilammy opened this issue 4 years ago • 0 comments

Currently, in order to use json_object! macro you also have to import inlined_json_object! macro. This is codified as the recommended way to just use json_in_type::*; and import everything exported by json_object.

It's not strictly necessary as json_object! macro could be restructured include inlined_json_object!. The typical trick is to reserve some special branch:

macro_rules! json_object {
    (inlined @ key : $key:ident, value : $value:expr, next : $next:expr) => {
        // inline inlined_json_object! implementation here
    };
}

This would make it unnecessary to use blanket imports (which pollutes namespace a bit), or import some extra implementation detail magic macros as well.

Though, note that inlined_json_object! has been exported and removing it might be a breaking change for those who have explicitly imported it. Optimizing json_object! might also be a “breaking change” of a different kind (since inlined_json_object! would no longer be used, all its imports would cause “unused import” warnings).

ilammy avatar Apr 07 '21 03:04 ilammy