Skip to main content

Lintable

Struct Lintable 

Source
pub struct Lintable<T> {
    content: T,
    raw: Option<String>,
    fix: bool,
    path: PathBuf,
    workspace_dir: PathBuf,
    modified: bool,
    failed: AtomicBool,
}
Expand description

A wrapper around file content for linting.

Most lints will want to use the Deref impl to access the content directly, but this also provides utilities for reporting errors and making fixes.

Fields§

§content: T§raw: Option<String>§fix: bool§path: PathBuf§workspace_dir: PathBuf§modified: bool§failed: AtomicBool

Implementations§

Source§

impl Lintable<String>

Source

fn from_file( path: &Path, ctx: &FmtCtx, workspace_dir: &Path, ) -> Result<Option<Self>>

Read a text file into a Lintable<String>.

Returns None for binary (non-UTF-8) files.

Source§

impl Lintable<DocumentMut>

Source

fn from_file(path: &Path, ctx: &FmtCtx, workspace_dir: &Path) -> Result<Self>

Read a Cargo.toml file into a Lintable<DocumentMut>.

This can be from a crate or a workspace.

Source§

impl<T> Lintable<T>

Source

pub fn path(&self) -> &Path

Get the path of this file relative to the workspace root, for use in error messages.

Source

pub fn raw(&self) -> Option<&str>

Get the original raw file content as a string, for lints that need to do their own parsing.

If the file content is already a string this will be None. This field is not modified when fixes are made.

Source

pub fn fix(&mut self, description: &str, op: impl FnOnce(&mut T))

If fix is enabled, apply the given fix operation to the content and mark it modified. If fix is not enabled, report an error with the given description.

Source

pub fn unfixable(&self, description: &str)

Report an error with the given description that cannot be automatically fixed.

Source

fn finalize(self) -> Result<bool>
where T: Display,

If modified, write the content back to the file. Return whether any errors were reported.

Trait Implementations§

Source§

impl<T> Deref for Lintable<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<T> !Freeze for Lintable<T>

§

impl<T> RefUnwindSafe for Lintable<T>
where T: RefUnwindSafe,

§

impl<T> Send for Lintable<T>
where T: Send,

§

impl<T> Sync for Lintable<T>
where T: Sync,

§

impl<T> Unpin for Lintable<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Lintable<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Lintable<T>
where T: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more