Print arrays and maps with to_debug.

This commit is contained in:
Stephen Chung
2020-11-30 11:20:51 +08:00
parent 65a4ceb3be
commit 1004bca5b5
9 changed files with 113 additions and 19 deletions

View File

@@ -38,3 +38,5 @@ is an alias to `Rc<String>` or `Arc<String>` (depending on the [`sync`] feature)
Any modification done to a Rhai string will cause the string to be cloned and the modifications made to the copy.
The `to_string` function converts a standard type into a [string] for display purposes.
The `to_debug` function converts a standard type into a [string] in debug format.

View File

@@ -61,7 +61,7 @@ mod MyEnumModule {
}
}
// Printing
#[rhai(global, name = "to_string", name = "print", name = "debug")]
#[rhai(global, name = "to_string", name = "print", name = "to_debug", name = "debug")]
pub fn to_string(a: &mut MyEnum) -> String {
format!("{:?}", a))
}

View File

@@ -11,6 +11,7 @@ is `T: Display + Debug`):
| ----------- | ---------------------------------------------- | ---------------------------- | -------------------------------------------------------------------- |
| `to_string` | <code>\|x: &mut T\| -> String</code> | `x.to_string()` | converts the custom type into a [string] |
| `print` | <code>\|x: &mut T\| -> String</code> | `x.to_string()` | converts the custom type into a [string] for the [`print`] statement |
| `to_debug` | <code>\|x: &mut T\| -> String</code> | `format!("{:?}", x)` | converts the custom type into a [string] in debug format |
| `debug` | <code>\|x: &mut T\| -> String</code> | `format!("{:?}", x)` | converts the custom type into a [string] for the [`debug`] statement |
| `+` | <code>\|s: &str, x: T\| -> String</code> | `format!("{}{}", s, x)` | concatenates the custom type with another [string] |
| `+` | <code>\|x: &mut T, s: &str\| -> String</code> | `x.to_string().push_str(s);` | concatenates another [string] with the custom type |