pub struct LayoutConfig<T: Layout> {
pub is_opener: fn(&T) -> bool,
pub is_bracket_open: Option<fn(&T) -> bool>,
pub is_bracket_close: Option<fn(&T) -> bool>,
pub is_carry_opener: Option<fn(&T) -> bool>,
pub mode: LayoutMode,
pub opener_rule: OpenerRule,
pub tab_width: usize,
/* private fields */
}Expand description
Configuration for crate::LayoutLexer.
Predicates are plain function pointers so that no allocation or Box<dyn Fn> is needed; users pass an fn item such as is_my_opener defined
elsewhere.
Fields§
§is_opener: fn(&T) -> boolDoes this token start a layout block? The next token’s column becomes
the new block’s indent level. For Haskell: do | where | let | of.
is_bracket_open: Option<fn(&T) -> bool>Does this token open a bracket group that suppresses layout? Typical:
( [ {. While brackets are open no virtual tokens are emitted. None
disables.
is_bracket_close: Option<fn(&T) -> bool>Does this token close a bracket group? Pairs with is_bracket_open.
None disables.
is_carry_opener: Option<fn(&T) -> bool>Does this token keep its opener status across an immediately following
bracket group on the same line? With fn in this set, fn(x) followed
by an indented line opens a block after the closing paren, which gives
trailing-block-argument syntax. None disables.
mode: LayoutModeOff-side rule variant.
opener_rule: OpenerRuleWhether openers fire unconditionally or only on newline plus indent.
tab_width: usizeColumns per tab character. Defaults to 1.
Implementations§
Source§impl<T: Layout> LayoutConfig<T>
impl<T: Layout> LayoutConfig<T>
Sourcepub fn new(is_opener: fn(&T) -> bool) -> Self
pub fn new(is_opener: fn(&T) -> bool) -> Self
Build a new config with the given opener predicate, no brackets, no
carry openers, Lazy mode, Always openers, and tab_width = 1.
Sourcepub fn with_brackets(self, open: fn(&T) -> bool, close: fn(&T) -> bool) -> Self
pub fn with_brackets(self, open: fn(&T) -> bool, close: fn(&T) -> bool) -> Self
Enable bracket pairs that suppress layout while open.
Sourcepub fn with_carry_openers(self, is_carry: fn(&T) -> bool) -> Self
pub fn with_carry_openers(self, is_carry: fn(&T) -> bool) -> Self
Enable carry openers: tokens whose opener status survives an immediately following bracket group started on the same line.
Sourcepub const fn with_mode(self, mode: LayoutMode) -> Self
pub const fn with_mode(self, mode: LayoutMode) -> Self
Set the off-side rule variant.
Sourcepub const fn with_opener_rule(self, rule: OpenerRule) -> Self
pub const fn with_opener_rule(self, rule: OpenerRule) -> Self
Set when openers fire.
Sourcepub const fn with_tab_width(self, tab_width: usize) -> Self
pub const fn with_tab_width(self, tab_width: usize) -> Self
Set the tab-to-column expansion.