Skip to content

Commit c382e6b

Browse files
authored
Merge pull request #1234 from godot-rust/qol/vdict
Start phasing out `dict!` macro in favor of `vdict!`
2 parents c1a41c9 + d7507dd commit c382e6b

File tree

11 files changed

+87
-76
lines changed

11 files changed

+87
-76
lines changed

godot-core/src/builtin/collections/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ impl<T: ArrayElement> PartialOrd for Array<T> {
15311531
/// # See also
15321532
/// To create an `Array` of variants, see the [`varray!`] macro.
15331533
///
1534-
/// For dictionaries, a similar macro [`dict!`] exists.
1534+
/// For dictionaries, a similar macro [`vdict!`] exists.
15351535
#[macro_export]
15361536
macro_rules! array {
15371537
($($elements:expr),* $(,)?) => {
@@ -1558,7 +1558,7 @@ macro_rules! array {
15581558
/// # See also
15591559
/// To create a typed `Array` with a single element type, see the [`array!`] macro.
15601560
///
1561-
/// For dictionaries, a similar macro [`dict!`] exists.
1561+
/// For dictionaries, a similar macro [`vdict!`] exists.
15621562
///
15631563
/// To construct slices of variants, use [`vslice!`].
15641564
#[macro_export]
@@ -1604,7 +1604,7 @@ macro_rules! varray {
16041604
/// # See also
16051605
/// To create typed and untyped `Array`s, use the [`array!`] and [`varray!`] macros respectively.
16061606
///
1607-
/// For dictionaries, a similar macro [`dict!`] exists.
1607+
/// For dictionaries, a similar macro [`vdict!`] exists.
16081608
#[macro_export]
16091609
macro_rules! vslice {
16101610
// Note: use to_variant() and not Variant::from(), as that works with both references and values

godot-core/src/builtin/collections/dictionary.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use std::{fmt, ptr};
3434
/// dict.set(coord, "Tile77");
3535
///
3636
/// // Or create the same dictionary in a single expression.
37-
/// let dict = dict! {
37+
/// let dict = vdict! {
3838
/// "str": "Hello",
3939
/// "num": 23,
4040
/// coord: "Tile77",
@@ -762,10 +762,10 @@ fn u8_to_bool(u: u8) -> bool {
762762
///
763763
/// # Example
764764
/// ```no_run
765-
/// use godot::builtin::{dict, Variant};
765+
/// use godot::builtin::{vdict, Variant};
766766
///
767767
/// let key = "my_key";
768-
/// let d = dict! {
768+
/// let d = vdict! {
769769
/// "key1": 10,
770770
/// "another": Variant::nil(),
771771
/// key: true,
@@ -777,7 +777,7 @@ fn u8_to_bool(u: u8) -> bool {
777777
///
778778
/// For arrays, similar macros [`array!`][macro@crate::builtin::array] and [`varray!`][macro@crate::builtin::varray] exist.
779779
#[macro_export]
780-
macro_rules! dict {
780+
macro_rules! vdict {
781781
($($key:tt: $value:expr),* $(,)?) => {
782782
{
783783
let mut d = $crate::builtin::Dictionary::new();
@@ -791,3 +791,13 @@ macro_rules! dict {
791791
}
792792
};
793793
}
794+
795+
#[macro_export]
796+
#[deprecated = "Migrate to `vdict!`. The name `dict!` will be used in the future for typed dictionaries."]
797+
macro_rules! dict {
798+
($($key:tt: $value:expr),* $(,)?) => {
799+
$crate::vdict!(
800+
$($key: $value),*
801+
)
802+
};
803+
}

godot-core/src/builtin/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
//! [extended documentation page](../__docs/index.html#builtin-api-design).
1515
1616
// Re-export macros.
17-
pub use crate::{array, dict, real, reals, varray};
17+
#[allow(deprecated)] // dict
18+
pub use crate::{array, dict, real, reals, varray, vdict};
1819

1920
// Re-export generated enums.
2021
pub use crate::gen::central::global_reexported_enums::{Corner, EulerOrder, Side, VariantOperator};
@@ -48,7 +49,7 @@ pub mod __prelude_reexport {
4849
pub use vectors::*;
4950

5051
pub use super::{EulerOrder, Side, VariantOperator, VariantType};
51-
pub use crate::{array, dict, real, reals, varray, vslice};
52+
pub use crate::{array, real, reals, varray, vdict, vslice};
5253
}
5354

5455
pub use __prelude_reexport::*;

godot-core/src/registry/rpc_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::classes::multiplayer_api::RpcMode;
1010
use crate::classes::multiplayer_peer::TransferMode;
1111
use crate::classes::Node;
1212
use crate::meta::{AsArg, ToGodot};
13-
use crate::{arg_into_ref, dict};
13+
use crate::{arg_into_ref, vdict};
1414

1515
/// Configuration for a remote procedure call, used with `#[rpc(config = ...)]`.
1616
///
@@ -45,7 +45,7 @@ impl RpcConfig {
4545

4646
/// Returns a [`Dictionary`] populated with the values required for a call to [`Node::rpc_config()`].
4747
pub fn to_dictionary(&self) -> Dictionary {
48-
dict! {
48+
vdict! {
4949
"rpc_mode": self.rpc_mode,
5050
"transfer_mode": self.transfer_mode,
5151
"call_local": self.call_local,

itest/rust/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn collect_inputs() -> Vec<Input> {
193193

194194
pushs!(inputs; Dictionary, Dictionary,
195195
r#"{"key": 83, -3: Vector2(1, 2), 0.03: true}"#,
196-
dict! { "key": 83, (-3): Vector2::new(1.0, 2.0), 0.03: true },
196+
vdict! { "key": 83, (-3): Vector2::new(1.0, 2.0), 0.03: true },
197197
true, true, None
198198
);
199199

itest/rust/src/builtin_tests/containers/callable_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use crate::framework::itest;
99
use godot::builtin::{
10-
array, dict, varray, vslice, Array, Callable, Color, GString, NodePath, StringName, Variant,
10+
array, varray, vdict, vslice, Array, Callable, Color, GString, NodePath, StringName, Variant,
1111
VariantArray, Vector2,
1212
};
1313
use godot::classes::{Node2D, Object, RefCounted};
@@ -102,7 +102,7 @@ fn callable_object_method() {
102102
#[cfg(since_api = "4.3")]
103103
fn callable_variant_method() {
104104
// Dictionary
105-
let dict = dict! { "one": 1, "value": 2 };
105+
let dict = vdict! { "one": 1, "value": 2 };
106106
let dict_get = Callable::from_variant_method(&dict.to_variant(), "get");
107107
assert_eq!(dict_get.call(vslice!["one"]), 1.to_variant());
108108

0 commit comments

Comments
 (0)