Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08baaaf

Browse files
authored
Merge pull request#1000 from schungx/master
Fix CustomType macro with sync feature
2 parents1602dd9 +91a1d26 commit08baaaf

File tree

7 files changed

+45
-21
lines changed

7 files changed

+45
-21
lines changed

‎CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Bug fixes
99

1010
* Modules loaded within a`ModuleResolversCollection` now properly enable access to the`scope` etc.
1111

12+
Enhancements
13+
-----------
14+
15+
*`CustomType` derive macro now supports generic types (thanks[`@ProphetOSpam`](https://github.com/ProphetOSpam)[#999](https://github.com/rhaiscript/rhai/pull/999)). The`rhai_codegen` crate dependency is bumped to`3.0.0` or later.
16+
1217

1318
Version 1.22.2
1419
==============

‎Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ num-traits = { version = "0.2.14", default-features = false }
2525
once_cell = {version ="1.20.1",default-features =false,features = ["race","portable-atomic","alloc"] }
2626
bitflags = {version ="2.3.3",default-features =false }
2727
smartstring = {version ="1.0.0",default-features =false }
28-
rhai_codegen = {version ="2.1.0",path ="codegen" }
28+
rhai_codegen = {version ="3.0.0",path ="codegen" }
2929

3030
no-std-compat = {git ="https://gitlab.com/jD91mZM2/no-std-compat.git",version ="0.4.1",default-features =false,features = ["alloc"],optional =true }
3131
libm = {version ="0.2.0",default-features =false,optional =true }
@@ -54,7 +54,7 @@ std = ["once_cell/std", "ahash/std", "num-traits/std", "smartstring/std"]
5454
#! ### Enable Special Functionalities
5555

5656
## Require that all data types implement `Send + Sync` (for multi-threaded usage).
57-
sync = ["no-std-compat?/compat_sync"]
57+
sync = ["no-std-compat?/compat_sync","rhai_codegen/sync"]
5858
## Add support for the [`Decimal`](https://crates.io/crates/rust_decimal) data type (acts as the system floating-point type under `no_float`).
5959
decimal = ["rust_decimal"]
6060
## Enable serialization/deserialization of Rhai data types via [`serde`](https://crates.io/crates/serde).

‎codegen/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name ="rhai_codegen"
3-
version ="2.2.0"
3+
version ="3.0.0"
44
edition ="2018"
55
resolver ="2"
66
authors = ["jhwgh1968","Stephen Chung"]
@@ -16,6 +16,7 @@ proc-macro = true
1616

1717
[features]
1818
default = []
19+
sync = []
1920
metadata = []
2021

2122
[dependencies]

‎codegen/src/custom_type.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ pub fn derive_custom_type_impl(input: DeriveInput) -> TokenStream {
147147
param
148148
.bounds
149149
.push(Lifetime::new("'static",Span::call_site()).into());
150+
151+
#[cfg(feature ="sync")]
152+
{
153+
param.bounds.push(
154+
TraitBound{
155+
paren_token:None,
156+
modifier: syn::TraitBoundModifier::None,
157+
lifetimes:None,
158+
path: syn::parse("Send".parse().unwrap()).unwrap(),
159+
}
160+
.into(),
161+
);
162+
param.bounds.push(
163+
TraitBound{
164+
paren_token:None,
165+
modifier: syn::TraitBoundModifier::None,
166+
lifetimes:None,
167+
path: syn::parse("Sync".parse().unwrap()).unwrap(),
168+
}
169+
.into(),
170+
);
171+
}
150172
}
151173

152174
quote!{

‎codegen/ui_tests/rhai_mod_inner_cfg_false.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ warning: unexpected `cfg` condition value: `unset_feature`
2121
11 | #[cfg(feature = "unset_feature")]
2222
| ^^^^^^^^^^^^^^^^^^^^^^^^^
2323
|
24-
= note: expected values for `feature` are: `default`and `metadata`
24+
= note: expected values for `feature` are: `default`, `metadata`,and `sync`
2525
= help: consider adding `unset_feature` as a feature in `Cargo.toml`
2626
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
2727
= note: `#[warn(unexpected_cfgs)]` on by default

‎src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -477,22 +477,10 @@ compile_error!("`only_i32` and `only_i64` cannot be used together");
477477
#[cfg(feature ="wasm-bindgen")]
478478
compile_error!("`wasm-bindgen` cannot be used with `no-std`");
479479

480-
#[cfg(feature ="no_std")]
481-
#[cfg(feature ="stdweb")]
482-
compile_error!("`stdweb` cannot be used with `no-std`");
483-
484480
#[cfg(target_family ="wasm")]
485481
#[cfg(feature ="no_std")]
486482
compile_error!("`no_std` cannot be used for WASM target");
487483

488484
#[cfg(not(target_family ="wasm"))]
489485
#[cfg(feature ="wasm-bindgen")]
490486
compile_error!("`wasm-bindgen` cannot be used for non-WASM target");
491-
492-
#[cfg(not(target_family ="wasm"))]
493-
#[cfg(feature ="stdweb")]
494-
compile_error!("`stdweb` cannot be used non-WASM target");
495-
496-
#[cfg(feature ="wasm-bindgen")]
497-
#[cfg(feature ="stdweb")]
498-
compile_error!("`wasm-bindgen` and `stdweb` cannot be used together");

‎tests/build_type.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,26 @@ fn test_build_type_generics() {
256256
x:T,
257257
}
258258

259+
#[cfg(not(feature ="sync"))]
259260
impl<T:Clone +'static>Foo<T>{
260261
fnbuild_extra(builder:&mutTypeBuilder<Self>){
261262
builder.with_fn("new_foo", |x:T|Self{ x});
262263
}
263264
}
264265

266+
#[cfg(feature ="sync")]
267+
impl<T:Send +Sync +Clone +'static>Foo<T>{
268+
fnbuild_extra(builder:&mutTypeBuilder<Self>){
269+
builder.with_fn("new_foo", |x:T|Self{ x});
270+
}
271+
}
272+
265273
letmut engine =Engine::new();
266274

267-
engine.build_type::<Foo<i64>>();
275+
engine.build_type::<Foo<INT>>();
268276
assert_eq!(
269277
engine
270-
.eval::<Foo<i64>>(
278+
.eval::<Foo<INT>>(
271279
r#"
272280
let foo = new_foo(3);
273281
foo
@@ -277,16 +285,16 @@ fn test_build_type_generics() {
277285
Foo{ x:3}
278286
);
279287

280-
engine.build_type::<Foo<&str>>();
288+
engine.build_type::<Foo<String>>();
281289
assert_eq!(
282290
engine
283-
.eval::<Foo<&str>>(
291+
.eval::<Foo<String>>(
284292
r#"
285293
let foo = new_foo("howdy!");
286294
foo
287295
"#
288296
)
289297
.unwrap(),
290-
Foo{ x:"howdy!"}
298+
Foo{ x:String::from("howdy!")}
291299
);
292300
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp