Skip to main content

ProviderChain

Struct ProviderChain 

Source
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

Source

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).

Source

pub fn of(provider: FormatProvider) -> Self

The single-provider chain, for the common defaults.

Source

pub fn iter(&self) -> Iter<'_, FormatProvider> ⓘ

The providers in resolution order — first available wins.

Source

pub fn is_empty(&self) -> bool

Whether the chain names no provider at all (the user switched the intent off).

Source

pub fn len(&self) -> usize

Number of providers in the chain.

Source

pub fn label(&self) -> String

Canonical string form. Round-trips with Self::parse.

Source

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 program

Trait Implementations§

Source§

impl Clone for ProviderChain

Source§

fn clone(&self) -> ProviderChain

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 Debug for ProviderChain

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ProviderChain

Source§

fn default() -> ProviderChain

Returns the “default value” for a type. Read more
Source§

impl Display for ProviderChain

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for ProviderChain

Source§

impl PartialEq for ProviderChain

Source§

fn eq(&self, other: &ProviderChain) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ProviderChain

Auto Trait Implementations§

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.