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§
- Custom
custom
- Wraps some value and its output function to be used for output.
- 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.
- NoOutput
path
- Helper type to mark something that shouldn’t be outputted.
Used as replacer in some instantiations of [
Path
]. - Parameterized
params
- Implements actual
fmt::Display
output for referenced examplar of type T according to given Params. Compare with the example above. - Passage
( list
orstruct
) andinstant
- Type implementing Kind and used to mark types which are treated as Iterator and not IntoIterator.
- Path
Like path
- Special type which helps to output different path-like types.
Everything that produces
fmt::Display
items while being iterated can be outputted this way. Implementscrate::Params
and intended to be used as argument ofcrate::WithParams::with_params
. - 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 embed
andlist
- Trait letting to define embedding of implementing type list output into other type list output.
- Embed
Struct embed
andstruct
- 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.
- Params
params
- Intended to perform output of given type T examplar according to inner state.
The same type may implement Params to output different types.
Designed to be used either with
Parameterized
(see examples below) or withcrate::Custom
(see current example). - With
Params params
- Simplifies outputting with some Params implementor for type which implements WithParams.
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 embed
andlist
- 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 embed
andstruct
- 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.