Printing for Custom Types

To use custom types for print and debug, or convert a custom type into a string, it is necessary that the following functions be registered (assuming the custom type is T: Display + Debug):

FunctionSignatureTypical implementationUsage
to_string|x: &mut T| -> Stringx.to_string()converts the custom type into a string
to_debug|x: &mut T| -> Stringformat!("{:?}", x)converts the custom type into a string in debug format

The following functions are implemented using to_string() or to_debug() by default, but can be overloaded with custom versions:

FunctionSignatureDefaultUsage
print|x: &mut T| -> Stringto_stringconverts the custom type into a string for the print statement
debug|x: &mut T| -> Stringto_debugconverts the custom type into a string for the debug statement
+ operator|s: &str, x: T| -> Stringto_stringconcatenates the custom type with another string
+ operator|x: &mut T, s: &str| -> Stringto_stringconcatenates another string with the custom type
+= operator|s: &mut ImmutableString, x: T|to_stringappends the custom type to an existing string