-
-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathmod.rs
More file actions
160 lines (135 loc) · 4.51 KB
/
Copy pathmod.rs
File metadata and controls
160 lines (135 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Copyright (c) godot-rust; Bromeon and contributors.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
//! Built-in types like `Vector2`, `GString` and `Variant`.
//!
//! Please read the [book chapter](https://godot-rust.github.io/book/godot-api/builtins.html) about builtin types.
//!
//! # API design
//! API design behind the builtin types (and some wider parts of the library) is elaborated in the
//! [extended documentation page](../__docs/index.html#builtin-api-design).
// Re-export generated enums.
pub use crate::gen::central::global_reexported_enums::{Corner, EulerOrder, Side, VariantOperator};
// Not yet public.
pub(crate) use crate::gen::central::VariantDispatch;
pub use crate::sys::VariantType;
// Re-export macros.
#[allow(deprecated)] // dict
pub use crate::{array, dict, real, reals, varray, vdict};
#[doc(hidden)]
pub mod __prelude_reexport {
#[rustfmt::skip] // Do not reorder.
use super::*;
pub use aabb::*;
pub use basis::*;
pub use callable::*;
pub use collections::containers::*;
pub use color::*;
pub use color_hsv::*;
pub use plane::*;
pub use projection::*;
pub use quaternion::*;
pub use real_inner::*;
pub use rect2::*;
pub use rect2i::*;
pub use rid::*;
pub use signal::*;
pub use string::{Encoding, GString, NodePath, StringName};
pub use transform2d::*;
pub use transform3d::*;
pub use variant::*;
pub use vectors::*;
pub use super::math::XformInv;
pub use super::{EulerOrder, Side, VariantOperator, VariantType};
pub use crate::{array, real, reals, varray, vdict, vslice};
#[allow(deprecated)]
#[rustfmt::skip] // Do not reorder.
pub use crate::dict;
#[cfg(feature = "trace")] // Test only.
pub use crate::static_sname;
}
pub use __prelude_reexport::*;
/// Math-related functions and traits like [`ApproxEq`][math::ApproxEq].
pub mod math;
/// Iterator types for arrays and dictionaries.
pub mod iter {
pub use super::collections::iterators::*;
}
/// Specialized types related to Godot's various string implementations.
pub mod strings {
pub use super::string::{
ExGStringFind, ExGStringSplit, ExStringNameFind, ExStringNameSplit, TransientStringNameOrd,
};
}
pub(crate) mod meta_reexport {
pub use super::collections::PackedArrayElement;
}
// ----------------------------------------------------------------------------------------------------------------------------------------------
// Implementation
// Modules exporting declarative macros must appear first.
mod macros;
// Other modules
mod aabb;
mod basis;
mod callable;
mod collections;
mod color;
mod color_constants; // After color, so that constants are listed after methods in docs (alphabetic ensures that).
mod color_hsv;
mod plane;
mod projection;
mod quaternion;
mod rect2;
mod rect2i;
mod rid;
mod signal;
mod string;
mod transform2d;
mod transform3d;
mod variant;
mod vectors;
// Rename imports because we re-export a subset of types under same module names.
#[path = "real.rs"]
mod real_inner;
#[doc(hidden)]
pub mod inner {
pub use crate::gen::builtin_classes::*;
}
#[macro_export]
macro_rules! declare_hash_u32_method {
( $( $docs:tt )+ ) => {
$( $docs )+
pub fn hash_u32(&self) -> u32 {
self.as_inner().hash().try_into().expect("Godot hashes are uint32_t")
}
}
}
// ----------------------------------------------------------------------------------------------------------------------------------------------
// Conversion functions
pub(crate) fn to_i64(i: usize) -> i64 {
i.try_into().unwrap()
}
pub(crate) fn to_usize(i: i64) -> usize {
i.try_into().unwrap()
}
// ----------------------------------------------------------------------------------------------------------------------------------------------
// #[test] utils for serde
#[cfg(all(test, feature = "serde"))]
pub(crate) mod test_utils {
use serde::{Deserialize, Serialize};
pub(crate) fn roundtrip<T>(value: &T, expected_json: &str)
where
T: for<'a> Deserialize<'a> + Serialize + PartialEq + std::fmt::Debug,
{
let json: String = serde_json::to_string(value).unwrap();
let back: T = serde_json::from_str(json.as_str()).unwrap();
assert_eq!(back, *value, "serde round-trip changes value");
assert_eq!(
json, expected_json,
"value does not conform to expected JSON"
);
}
}