macro_rules! graphql_value {
(@array [$($elems:expr,)*]) => { ... };
(@array [$($elems:expr),*]) => { ... };
(@array [$($elems:expr,)*] null $($rest:tt)*) => { ... };
(@array [$($elems:expr,)*] None $($rest:tt)*) => { ... };
(@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => { ... };
(@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => { ... };
(@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => { ... };
(@array [$($elems:expr,)*] $last:expr) => { ... };
(@array [$($elems:expr),*] , $($rest:tt)*) => { ... };
(@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => { ... };
(@object $object:ident () () ()) => { ... };
(@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => { ... };
(@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => { ... };
(@object $object:ident [$($key:tt)+] ($value:expr)) => { ... };
(@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { ... };
(@object $object:ident ($($key:tt)+) (: None $($rest:tt)*) $copy:tt) => { ... };
(@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { ... };
(@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { ... };
(@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { ... };
(@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { ... };
(@object $object:ident ($($key:tt)+) (:) $copy:tt) => { ... };
(@object $object:ident ($($key:tt)+) () $copy:tt) => { ... };
(@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => { ... };
(@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => { ... };
(@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { ... };
(@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => { ... };
(@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { ... };
(@unexpected) => { ... };
([ $($arr:tt)* ]$(,)?) => { ... };
({}$(,)?) => { ... };
({ $($map:tt)+ }$(,)?) => { ... };
(null$(,)?) => { ... };
(None$(,)?) => { ... };
($e:expr$(,)?) => { ... };
}
Expand description
Constructs Value
s via JSON-like syntax.
Value
objects are used mostly when creating custom errors from fields.
Value::Object
key should implement AsRef
<
str
>
.
let code = 200;
let features = ["key", "value"];
let value: Value = graphql_value!({
"code": code,
"success": code == 200,
"payload": {
features[0]: features[1],
},
});
ยงExample
Resulting JSON will look just like what you passed in.
graphql_value!(null);
graphql_value!(1234);
graphql_value!("test");
graphql_value!([1234, "test", true]);
graphql_value!({"key": "value", "foo": 1234});