pub struct ProviderChain(pub Vec<FormatProvider>);Expand description
An ordered list of providers for one intent.
Written comma-separated: :set format.reformat=lsp,lang-default.
A command line in an external: rung may not contain a comma —
the comma is the chain separator and there is no escape. This is a
deliberate limit rather than an oversight: the alternative is a
quoting grammar inside a :set value, which is a lot of machinery
for a case (--config a,b) that a one-line wrapper script solves.
The error message says so when it bites.
Tuple Fields§
§0: Vec<FormatProvider>Implementations§
Source§impl ProviderChain
impl ProviderChain
Sourcepub fn new(providers: Vec<FormatProvider>) -> Self
pub fn new(providers: Vec<FormatProvider>) -> Self
A chain trying providers in order. An empty vector is a valid
“this intent does nothing” chain (see Self::parse).
Sourcepub fn of(provider: FormatProvider) -> Self
pub fn of(provider: FormatProvider) -> Self
The single-provider chain, for the common defaults.
Sourcepub fn iter(&self) -> Iter<'_, FormatProvider> ⓘ
pub fn iter(&self) -> Iter<'_, FormatProvider> ⓘ
The providers in resolution order — first available wins.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the chain names no provider at all (the user switched the intent off).
Sourcepub fn label(&self) -> String
pub fn label(&self) -> String
Canonical string form. Round-trips with Self::parse.
Sourcepub fn parse(s: &str) -> Result<Self, String>
pub fn parse(s: &str) -> Result<Self, String>
Parse a comma-separated chain.
The empty string is a valid EMPTY chain, not an error: it is how a user says “this intent does nothing here”, and rejecting it would leave no way to express that short of a sentinel value. An empty chain reports “nothing configured” at resolution rather than falling back to a default the user just removed.
§Errors
A human-readable message for an empty entry (lsp,,native) or any
rung FormatProvider::parse rejects.
§Examples
use lattice_core::{FormatProvider, ProviderChain};
let chain = ProviderChain::parse("lsp, external:prettier --stdin-filepath %")
.unwrap_or_default();
assert_eq!(
chain.iter().cloned().collect::<Vec<_>>(),
[
FormatProvider::Lsp,
FormatProvider::External("prettier --stdin-filepath %".into()),
],
);
assert_eq!(chain.label(), "lsp,external:prettier --stdin-filepath %");
assert!(ProviderChain::parse("").is_ok_and(|c| c.is_empty()));
assert!(ProviderChain::parse("nativ").is_err()); // typo, not a programTrait Implementations§
Source§impl Clone for ProviderChain
impl Clone for ProviderChain
Source§fn clone(&self) -> ProviderChain
fn clone(&self) -> ProviderChain
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 ProviderChain
impl Debug for ProviderChain
Source§impl Default for ProviderChain
impl Default for ProviderChain
Source§fn default() -> ProviderChain
fn default() -> ProviderChain
Source§impl Display for ProviderChain
impl Display for ProviderChain
impl Eq for ProviderChain
Source§impl PartialEq for ProviderChain
impl PartialEq for ProviderChain
impl StructuralPartialEq for ProviderChain
Auto Trait Implementations§
impl Freeze for ProviderChain
impl RefUnwindSafe for ProviderChain
impl Send for ProviderChain
impl Sync for ProviderChain
impl Unpin for ProviderChain
impl UnsafeUnpin for ProviderChain
impl UnwindSafe for ProviderChain
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.