pub trait Cost:
Ord
+ Add
+ Clone
+ Debug { }Expand description
A measurement of the badness of a particular printing layout.
Doc is generic on the Cost type it can be used with, since
a document can contain cost nodes that increase the cost of
certain paths.
When a document is being printed, costs are assigned
by a CostFactory. This determines the badness of
text/newline nodes based on their
location in the layout. The printer will then try to minimize this cost
overall.
A DefaultCost and DefaultCostFactory is provided, and
Doc will default to using the DefaultCost if no generic
parameter is given to it.
§Requirements for costs
A Cost must satisfy several properties for the printer to be able to use
it correctly:
a <= bmust be a total order. This requirement is imposed by theOrdtrait.a + b(via theAddtrait) must be commutative and associative.- If
a <= bandc <= d, thena + c <= b + d.
There are additional
requirements for the functions
on the CostFactory.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.