Merge ser/de modules.

This commit is contained in:
Stephen Chung 2020-10-10 13:43:14 +08:00
parent 612ecc4ebc
commit dd9f58f323
6 changed files with 9 additions and 8 deletions

View File

@ -14,6 +14,7 @@ Breaking changes
* `GlobalFileModuleResolver` is removed because its performance gain over the `FileModuleResolver` is no longer very significant. * `GlobalFileModuleResolver` is removed because its performance gain over the `FileModuleResolver` is no longer very significant.
* The following `EvalAltResult` variants are removed and merged into `EvalAltResult::ErrorMismatchDataType`: `ErrorCharMismatch`, `ErrorNumericIndexExpr`, `ErrorStringIndexExpr`, `ErrorImportExpr`, `ErrorLogicGuard`, `ErrorBooleanArgMismatch` * The following `EvalAltResult` variants are removed and merged into `EvalAltResult::ErrorMismatchDataType`: `ErrorCharMismatch`, `ErrorNumericIndexExpr`, `ErrorStringIndexExpr`, `ErrorImportExpr`, `ErrorLogicGuard`, `ErrorBooleanArgMismatch`
* `Scope::iter_raw` returns an iterator with an additional field indicating whether the variable is constant or not. * `Scope::iter_raw` returns an iterator with an additional field indicating whether the variable is constant or not.
* `rhai::ser` and `rhai::de` namespaces are merged into `rhai::serde`.
New features New features
------------ ------------

View File

@ -14,12 +14,12 @@ A [`Dynamic`] can be seamlessly converted to and from a type that implements
Serialization Serialization
------------- -------------
The function `rhai::ser::to_dynamic` automatically converts any Rust type that implements The function `rhai::serde::to_dynamic` automatically converts any Rust type that implements
[`serde::Serialize`](https://docs.serde.rs/serde/trait.Serialize.html) into a [`Dynamic`]. [`serde::Serialize`](https://docs.serde.rs/serde/trait.Serialize.html) into a [`Dynamic`].
This is usually not necessary because using [`Dynamic::from`][`Dynamic`] is much easier and is essentially This is usually not necessary because using [`Dynamic::from`][`Dynamic`] is much easier and is essentially
the same thing. The only difference is treatment for integer values. `Dynamic::from` will keep the different the same thing. The only difference is treatment for integer values. `Dynamic::from` will keep the different
integer types intact, while `rhai::ser::to_dynamic` will convert them all into [`INT`][standard types] integer types intact, while `rhai::serde::to_dynamic` will convert them all into [`INT`][standard types]
(i.e. the system integer type which is `i64` or `i32` depending on the [`only_i32`] feature). (i.e. the system integer type which is `i64` or `i32` depending on the [`only_i32`] feature).
In particular, Rust `struct`'s (or any type that is marked as a `serde` map) are converted into [object maps] In particular, Rust `struct`'s (or any type that is marked as a `serde` map) are converted into [object maps]
@ -27,11 +27,11 @@ while Rust `Vec`'s (or any type that is marked as a `serde` sequence) are conver
While it is also simple to serialize a Rust type to `JSON` via `serde`, While it is also simple to serialize a Rust type to `JSON` via `serde`,
then use [`Engine::parse_json`]({{rootUrl}}/language/json.md) to convert it into an [object map], then use [`Engine::parse_json`]({{rootUrl}}/language/json.md) to convert it into an [object map],
`rhai::ser::to_dynamic` serializes it to [`Dynamic`] directly via `serde` without going through the `JSON` step. `rhai::serde::to_dynamic` serializes it to [`Dynamic`] directly via `serde` without going through the `JSON` step.
```rust ```rust
use rhai::{Dynamic, Map}; use rhai::{Dynamic, Map};
use rhai::ser::to_dynamic; use rhai::serde::to_dynamic;
#[derive(Debug, serde::Serialize)] #[derive(Debug, serde::Serialize)]
struct Point { struct Point {
@ -64,7 +64,7 @@ map.is::<Map>() == true;
Deserialization Deserialization
--------------- ---------------
The function `rhai::de::from_dynamic` automatically converts a [`Dynamic`] value into any Rust type The function `rhai::serde::from_dynamic` automatically converts a [`Dynamic`] value into any Rust type
that implements [`serde::Deserialize`](https://docs.serde.rs/serde/trait.Deserialize.html). that implements [`serde::Deserialize`](https://docs.serde.rs/serde/trait.Deserialize.html).
In particular, [object maps] are converted into Rust `struct`'s (or any type that is marked as In particular, [object maps] are converted into Rust `struct`'s (or any type that is marked as
@ -73,7 +73,7 @@ as a `serde` sequence).
```rust ```rust
use rhai::{Engine, Dynamic}; use rhai::{Engine, Dynamic};
use rhai::de::from_dynamic; use rhai::serde::from_dynamic;
#[derive(Debug, serde::Deserialize)] #[derive(Debug, serde::Deserialize)]
struct Point { struct Point {

View File

@ -78,7 +78,7 @@ impl<'de> DynamicDeserializer<'de> {
/// # #[cfg(not(feature = "no_object"))] /// # #[cfg(not(feature = "no_object"))]
/// # { /// # {
/// use rhai::{Dynamic, Array, Map, INT}; /// use rhai::{Dynamic, Array, Map, INT};
/// use rhai::de::from_dynamic; /// use rhai::serde::from_dynamic;
/// use serde::Deserialize; /// use serde::Deserialize;
/// ///
/// #[derive(Debug, Deserialize, PartialEq)] /// #[derive(Debug, Deserialize, PartialEq)]

View File

@ -55,7 +55,7 @@ impl DynamicSerializer {
/// # #[cfg(not(feature = "no_float"))] /// # #[cfg(not(feature = "no_float"))]
/// # { /// # {
/// use rhai::{Dynamic, Array, Map, INT}; /// use rhai::{Dynamic, Array, Map, INT};
/// use rhai::ser::to_dynamic; /// use rhai::serde::to_dynamic;
/// use serde::Serialize; /// use serde::Serialize;
/// ///
/// #[derive(Debug, serde::Serialize, PartialEq)] /// #[derive(Debug, serde::Serialize, PartialEq)]