Crate cubob

Crate cubob 

Source
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§

Customcustom
Wraps some value and its output function to be used for output.
Fieldfield
Lets to output key-value pair regarding the propagated value of output alternativeness.
InstantListlist and instant
Struct used to simplify displaying of any iterable lists.
InstantStructstruct and instant
Struct used to simplify displaying of any iterable maps.
ListShowlist
Lets to output some listed data regarding the propagated value of output alternativeness.
NoOutputpath
Helper type to mark something that shouldn’t be outputted. Used as replacer in some instantiations of [Path].
Parameterizedparams
Implements actual fmt::Display output for referenced examplar of type T according to given Params. Compare with the example above.
Passage(list or struct) and instant
Type implementing Kind and used to mark types which are treated as Iterator and not IntoIterator.
PathLikepath
Special type which helps to output different path-like types. Everything that produces fmt::Display items while being iterated can be outputted this way. Implements crate::Params and intended to be used as argument of crate::WithParams::with_params.
Source(list or struct) and instant
Type implementing Kind and used to mark types which are treated as IntoIterator and not Iterator.
StructShowstruct
Lets to output some structure regarding the propagated value of output alternativeness.

Enums§

Alternate
Alternate mode to use while outputting.

Traits§

DisplayPairstruct
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.
EmbedListembed and list
Trait letting to define embedding of implementing type list output into other type list output.
EmbedStructembed and struct
Trait letting to define embedding of implementing type struct output into other type struct output.
Iterable(list or struct) and instant
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 or struct) and instant
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.
Paramsparams
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 with crate::Custom (see current example).
WithParamsparams
Simplifies outputting with some Params implementor for type which implements WithParams.

Functions§

display_listlist
Performs the whole list output routine from creation of ListShow examplar to finishing. Works with slice, always inherits alternate mode.
display_list_from_embedembed and list
Routine to simplify Display implementation for type which already implements EmbedList.
display_list_from_iterlist
Performs the whole list output routine from creation of ListShow examplar to finishing. Works with iterator, always inherits alternate mode.
display_structstruct
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_embedembed and struct
Routine to simplify Display implementation for type which already implements EmbedStruct.
display_struct_from_iterstruct
Performs the whole struct output routine from creation of StructShow examplar to finishing. Works with iterator, always inherits alternate mode.