Skip to main content

SourceState

Struct SourceState 

Source
pub struct SourceState {
    pub line_count: usize,
    /* private fields */
}
Available on crate feature markdown-preview only.
Expand description

Source state for markdown content management.

Manages the markdown source (string or file) and tracks line count.

Fields§

§line_count: usize

Source file line count (for accurate status bar display).

Implementations§

Source§

impl SourceState

Constructor for SourceState.

Source

pub fn new() -> SourceState

Create a new source state with no source.

Source§

impl SourceState

Content method for SourceState.

Source

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

Get the current content from the source.

§Returns

The markdown content, or None if no source is set.

Source§

impl SourceState

Is file source method for SourceState.

Source

pub fn is_file_source(&self) -> bool

Check if the source is file-based.

§Returns

true if the source is loaded from a file, false otherwise.

Source§

impl SourceState

Line count method for SourceState.

Source

pub fn line_count(&self) -> usize

Get the line count of the source content.

§Returns

The number of lines in the source content.

Source§

impl SourceState

Reload content if the file watcher detected changes.

Source

pub fn reload_if_changed(&mut self) -> Result<bool, Error>

Reload the source content if the watcher detected changes.

Returns Ok(true) when content changed and was reloaded.

Source§

impl SourceState

Reload source method for SourceState.

Source

pub fn reload_source(&mut self) -> Result<bool, Error>

Reload the source content from disk (for file-based sources).

This re-reads the file. The caller should check the return value and invalidate caches if content changed.

For string-based sources, this is a no-op.

§Returns
  • Ok(true) - Content changed, caller should invalidate caches.
  • Ok(false) - Content unchanged or source is string-based.
§Errors

Returns an error if the file cannot be read.

Source§

impl SourceState

Source

pub fn set_source_file(&mut self, path: impl AsRef<Path>) -> Result<(), Error>

Set a file-based markdown source.

This loads the file content and enables auto-reload support. Use reload_source() to check for and apply file changes.

Note: Caller should invalidate any caches after calling this.

§Arguments
  • path - Path to the markdown file.
§Errors

Returns an error if the file cannot be read.

Source§

impl SourceState

Set source string method for SourceState.

Source

pub fn set_source_string(&mut self, content: impl Into<String>)

Set a string-based markdown source.

Note: Caller should invalidate any caches after calling this.

§Arguments
  • content - The markdown content string.
Source§

impl SourceState

Source path method for SourceState.

Source

pub fn source_path(&self) -> Option<&Path>

Get the file path if this is a file-based source.

§Returns

The file path, or None if this is a string source or no source is set.

Trait Implementations§

Source§

impl Clone for SourceState

Source§

fn clone(&self) -> SourceState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SourceState

Source§

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

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

impl Default for SourceState

Default trait implementation for SourceState.

Source§

fn default() -> SourceState

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

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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