pub struct FormatterSpec {
pub program: &'static str,
pub args: &'static [&'static str],
pub filename_flag: Option<&'static str>,
}Expand description
How to invoke one external formatter.
Every formatter here reads the buffer on stdin and writes the result to stdout. That is deliberate and not merely convenient: a formatter that rewrites the file in place cannot be run against an unsaved buffer, and formatting only what is on disk is the wrong behaviour for an editor.
Fields§
§program: &'static strProgram name, resolved through PATH.
args: &'static [&'static str]Fixed arguments.
filename_flag: Option<&'static str>When set, the buffer’s path is appended as
<flag>=<path>. Several formatters need the filename to pick a
parser or find a config file even when reading stdin
(prettier --stdin-filepath, clang-format --assume-filename).
Implementations§
Source§impl FormatterSpec
impl FormatterSpec
Sourcepub fn for_lang(lang: Lang) -> Option<Self>
pub fn for_lang(lang: Lang) -> Option<Self>
The default formatter for lang, or None when there is no
obvious choice.
This table is a starting point, not a contract. Formatter
CLIs change flags across versions, and houses disagree about
which formatter to use at all. Every entry is one line to
correct, and formatprg overrides the whole thing per buffer.
Absent entries are not gaps to be filled on principle — a
language with no consensus formatter is better served by the
user naming one.
Sourcepub fn parse(s: &str) -> Option<Self>
pub fn parse(s: &str) -> Option<Self>
Parse a user-supplied formatter command line — an external: rung
of a format.* chain (RF.5), or the deprecated formatprg.
Whitespace-split, first word is the program. Leaked to
'static because FormatterSpec holds &'static str for the
built-in table’s sake; a handful of leaked option strings over a
session is not a leak worth a lifetime parameter through the
whole crate.
Returns None for an empty or whitespace-only string, which is
the “not configured” signal rather than an error.
Trait Implementations§
Source§impl Clone for FormatterSpec
impl Clone for FormatterSpec
Source§fn clone(&self) -> FormatterSpec
fn clone(&self) -> FormatterSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FormatterSpec
impl Debug for FormatterSpec
impl Eq for FormatterSpec
Source§impl PartialEq for FormatterSpec
impl PartialEq for FormatterSpec
impl StructuralPartialEq for FormatterSpec
Auto Trait Implementations§
impl Freeze for FormatterSpec
impl RefUnwindSafe for FormatterSpec
impl Send for FormatterSpec
impl Sync for FormatterSpec
impl Unpin for FormatterSpec
impl UnsafeUnpin for FormatterSpec
impl UnwindSafe for FormatterSpec
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more