pub struct DefaultCostFactory { /* private fields */ }Expand description
The default strategy for assigning costs to layouts.
This cost factory uses DefaultCost as its cost type. Its documentation
has more information about the components that make up the cost.
The default cost factory has two configurable parameters:
page_width: Required. The desired width of the document. Layouts that exceed this width will have a cost imposed based on how much they exceed it. The printer will choose a layout that fits within this width unless it is not possible to do so.computation_width: Optional. A more extreme width constraint. Documents that extend beyond this width will be “tainted”, and will not be explored further by the printer until it exhausts all untainted options. This constraint improves the performance of the printer. If not provided, it will default to1.2 * page_width.
This cost factory is used in the following situations:
- Calling
to_string()on a Doc will use this cost factory with a page width of 80. - Formatting a Doc using one of Rust’s formatting macros will use this cost factory. If a width parameter is given to the macro, it will be used as the page width. Otherwise, the default 80 characters will be used
- Calling
Doc::validatewill use this cost factory with the given page width.
None of these allow overriding the computation width,
as it isn’t usually necessary. If you want to use a
custom computation width, you can use Self::new and
Doc::validate_with_cost.
Implementations§
Trait Implementations§
Source§impl CostFactory for DefaultCostFactory
impl CostFactory for DefaultCostFactory
Source§fn newline(&self, _i: usize) -> Self::CostType
fn newline(&self, _i: usize) -> Self::CostType
Adds 1 to the second component of the cost.
The indentation level is ignored in this cost factory.
Source§fn text(&self, c: usize, l: usize) -> Self::CostType
fn text(&self, c: usize, l: usize) -> Self::CostType
Adds to the first component of the cost if the page width is exceeded.
If the text will not exceed the page width, no cost is imposed.
Source§type CostType = DefaultCost
type CostType = DefaultCost
The type of cost values that the factory will assign.