Print arrays and maps with to_debug.
This commit is contained in:
@@ -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.
|
||||
|
@@ -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))
|
||||
}
|
||||
|
@@ -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 |
|
||||
|
Reference in New Issue
Block a user