Comments (7)
My bad - I had forgotten that I had defined the assert_eq call myself, I had thought this was within rhai. I patched the assert_eq call to handle this extra type and now it works as expected. Thank you for the quick response. 🙏🏻
from rhai.
Well, you know that but Rhai doesn't. Unless you define the ==
operator for that enum type, Rhai can only assume that one opaque object is not the same as another...
So the solution is to define the comparison operators on your type.
from rhai.
I did that: here's the full macro I used:
macro_rules! create_enum_module {
($module:ident : $typ:ty => $($variant:ident),+) => {
#[export_module]
pub mod $module {
$(
#[allow(non_upper_case_globals)]
pub const $variant: $typ = <$typ>::$variant;
)*
#[rhai_fn(global, name = "to_string", name = "to_debug", pure)]
pub fn to_string(my_enum: &mut $typ) -> String {
format!("{my_enum:?}")
}
#[rhai_fn(global, name = "==", pure)]
pub fn eq(my_enum: &mut $typ, my_enum2: $typ) -> bool {
my_enum == &my_enum2
}
#[rhai_fn(global, name = "!=", pure)]
pub fn neq(my_enum: &mut $typ, my_enum2: $typ) -> bool {
my_enum != &my_enum2
}
}
};
}
from rhai.
I also tried defining the comparison operators directly on the enum type itself but I had the same error. Although the == comparison works when they are defined, using within assert_eq
fails.
from rhai.
May I ask whether you derived PartialEq
for your type?
EDIT: Probably yes since you can use ==
in Rust ..
from rhai.
Can you post your exact aasert_eq
call?
It seems like you are comparing with the results of a script call.
from rhai.
I tried various ways of calling it, always the same result:
assert_eq!(MyEnum::Foo,MyEnum::Foo);
assert_eq!(MyEnum::Foo,m.method_that_returns_enum_foo());
Edit: I might have found the issue, am checking now
from rhai.
Related Issues (20)
- to_float not implemented for float HOT 4
- check_struct_sizes and test_string_index test fails on 32 bit architectures HOT 6
- Add a no_plugin feature HOT 7
- Issue with `CustomType` getters HOT 2
- Customizing "let", syntax
- Customizing "let", "fn" syntax HOT 4
- Object definition syntax HOT 2
- on_var not called for variables in closures HOT 6
- `NativeCallContext` in `export_module` results in a "hidden lifetime parameters in types are deprecated" warning HOT 7
- Pre-compile scripts? HOT 6
- The `sync` feature flag is not compatible with `no_std` HOT 1
- Willingness to offer alternative Map types behind feature flags? HOT 1
- Rhai `no_std` appears to rely on `once_cell/alloc` but does not request it HOT 2
- Could you consider removing the semicolons at the end of the lines HOT 5
- Defining a pipeline operator? HOT 2
- min(f64, f64) function not found HOT 2
- A memory leak was discovered HOT 1
- A stack overflow vulnerability was found HOT 3
- [Question] Is there a way to turn a value with a lifetime into a `Dynamic` HOT 5
- Add `position` to `EvalAltResult::SystemError` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rhai.