Expand description
Some primitives to simplify implementation of structured data output in display mode. Usage example:
use core::fmt::{Display, Formatter, Result as FmtResult};
use cubob::display_struct;
struct Point {
x: i32,
y: i32,
}
struct Line {
a: Point,
b: Point,
}
impl Display for Point {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
display_struct(
f,
&[
(&"x", &self.x),
(&"y", &self.y),
],
)
}
}
impl Display for Line {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
display_struct(
f,
&[
(&"a", &self.a),
(&"b", &self.b),
],
)
}
}
let line = Line{ a: Point{ x: 0, y: 0}, b: Point{ x: 1, y: 1} };
println!("One-line: {}", line);
println!("Prettified: {:#}", line);
Structs§
- Field
field
- Lets to output key-value pair regarding the propagated value of output alternativeness.
- Instant
List list
andinstant
- Struct used to simplify displaying of any iterable lists.
- Instant
Struct struct
andinstant
- Struct used to simplify displaying of any iterable maps.
- List
Show list
- Lets to output some listed data regarding the propagated value of output alternativeness.
- Passage
( list
orstruct
) andinstant
- Type implementing Kind and used to mark types which are treated as Iterator and not IntoIterator.
- Source
( list
orstruct
) andinstant
- Type implementing Kind and used to mark types which are treated as IntoIterator and not Iterator.
- Struct
Show struct
- Lets to output some structure regarding the propagated value of output alternativeness.
Enums§
- Alternate
- Alternate mode to use while outputting.
Traits§
- Display
Pair struct
- Trait used to generalize over tuples of displayable types and references onto such tuples. Trait is not sealed and can be implementd for any other needed type.
- Embed
List list
andembed
- Trait letting to define embedding of implementing type list output into other type list output.
- Embed
Struct struct
andembed
- Trait letting to define embedding of implementing type struct output into other type struct output.
- Iterable
( list
orstruct
) andinstant
- Trait used to generalize over IntoIterator+Copy and Iterator+Clone types. Actual used source is defined via type parameter which should implement Kind trait. There can be some problems when type implements Iterator and Copy simultaneously: since every Iterator automatically implements IntoIterator, and Copy implementation requires Clone implementation too, such type will suit both alternatives and will cause conflict until explicit Kind specified. Trait is not sealed, so any user can define own Iterable implementation.
- Kind
( list
orstruct
) andinstant
- Special trait, generalizing all the types used to distinguish different types of iterable data sources. Those types can be either type, implementing IntoIterator and Copy (so usual reference on IntoIterator suits) or type, implementing Iterator and Clone. There can be some problems when type implements Iterator and Copy simultaneously: since every Iterator automatically implements IntoIterator, and Copy implementation requires Clone implementation too, such type will suit both alternatives and will cause conflict until explicit Kind specified. Trait is not sealed, so any user can define own kind and use it along with own Iterable implementation for that kind.
Functions§
- display_
list list
- Performs the whole list output routine from creation of ListShow examplar to finishing. Works with slice, always inherits alternate mode.
- display_
list_ from_ embed list
andembed
- Routine to simplify Display implementation for type which already implements EmbedList.
- display_
list_ from_ iter list
- Performs the whole list output routine from creation of ListShow examplar to finishing. Works with iterator, always inherits alternate mode.
- display_
struct struct
- Performs the whole struct output routine from creation of StructShow examplar to finishing (for example see the crate-level documentation). Works with slice, always inherits alternate mode.
- display_
struct_ from_ embed struct
andembed
- Routine to simplify Display implementation for type which already implements EmbedStruct.
- display_
struct_ from_ iter struct
- Performs the whole struct output routine from creation of StructShow examplar to finishing. Works with iterator, always inherits alternate mode.