Skip to main content

LayoutConfig

Struct LayoutConfig 

Source
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) -> bool

Does 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: LayoutMode

Off-side rule variant.

§opener_rule: OpenerRule

Whether openers fire unconditionally or only on newline plus indent.

§tab_width: usize

Columns per tab character. Defaults to 1.

Implementations§

Source§

impl<T: Layout> LayoutConfig<T>

Source

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.

Source

pub fn with_brackets(self, open: fn(&T) -> bool, close: fn(&T) -> bool) -> Self

Enable bracket pairs that suppress layout while open.

Source

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.

Source

pub const fn with_mode(self, mode: LayoutMode) -> Self

Set the off-side rule variant.

Source

pub const fn with_opener_rule(self, rule: OpenerRule) -> Self

Set when openers fire.

Source

pub const fn with_tab_width(self, tab_width: usize) -> Self

Set the tab-to-column expansion.

Trait Implementations§

Source§

impl<T: Clone + Layout> Clone for LayoutConfig<T>

Source§

fn clone(&self) -> LayoutConfig<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Layout> Debug for LayoutConfig<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for LayoutConfig<T>

§

impl<T> RefUnwindSafe for LayoutConfig<T>

§

impl<T> Send for LayoutConfig<T>

§

impl<T> Sync for LayoutConfig<T>

§

impl<T> Unpin for LayoutConfig<T>

§

impl<T> UnsafeUnpin for LayoutConfig<T>

§

impl<T> UnwindSafe for LayoutConfig<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.