Show
trait Show<T>
Source: compiler/src/builtin_docs/prelude/ops.hy Conversion to a display string, used by the %v format specifier.
int, float, byte, string, bool and unit have builtin
instances; tuples and records are shown structurally. A non-generic class
without an instance shows its type name, and a non-generic enum its
qualified variant name (E::V, payload elided). #[derive(Show)]
generates a field-by-field instance.
Required methods#
| Name | Description |
|---|---|
show | Returns the display form of value. |
Examples#
use tests::assert;
use string::{format};
class Point {
pub x: int,
pub y: int,
}
impl Show for Point {
pub fn show(Point p) -> string {
return format("(%i, %i)", p.x, p.y);
}
}
fn main() {
let p = new Point(1, 2);
assert!(show(p) == "(1, 2)");
assert!(format("at %v", p) == "at (1, 2)");
assert!(show(2.5) == "2.5");
}