pub struct Style<K> { /* private fields */ }Expand description
Formatting rules compiled against one language, ready for
format().
Build one with Rules::compile. Style::default is the empty style:
every gap keeps its original whitespace.
§Examples
use fmt_lang::{Rules, Space, Style, TokenRule};
// Kinds here are plain strings; a real language resolves names to its own
// kind type (for lang-forge: `|name| lang.kind(name)`).
let style: Style<&str> = Rules::new()
.token(TokenRule::new("+").around(Space::Single))
.compile(|name| ["+", "num"].into_iter().find(|k| *k == name))?;Implementations§
Source§impl<K> Style<K>
impl<K> Style<K>
Sourcepub fn with_touch(self, touch: fn(&str, &str) -> bool) -> Self
pub fn with_touch(self, touch: fn(&str, &str) -> bool) -> Self
Replaces the test that decides whether two tokens may be written with
nothing between them (default: can_touch).
The formatter calls it only where a rule would remove whitespace the
source had between two tokens; if it answers false, one space is kept.
A language whose lexer would read the touching texts differently (for
example one with a -1 literal, where - and 1 must not touch)
supplies its own test here.
§Examples
use fmt_lang::{can_touch, Style};
fn no_minus_digit(left: &str, right: &str) -> bool {
let digit = right.starts_with(|c: char| c.is_ascii_digit());
!(left.ends_with('-') && digit) && can_touch(left, right)
}
let style = Style::<u8>::default().with_touch(no_minus_digit);Trait Implementations§
Auto Trait Implementations§
impl<K> Freeze for Style<K>
impl<K> RefUnwindSafe for Style<K>
impl<K> Send for Style<K>
impl<K> Sync for Style<K>
impl<K> Unpin for Style<K>
impl<K> UnsafeUnpin for Style<K>
impl<K> UnwindSafe for Style<K>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more