Skip to main content

MarkdownSource

Enum MarkdownSource 

Source
pub enum MarkdownSource {
    String(String),
    File {
        path: PathBuf,
        content: String,
    },
}
Available on crate feature markdown-preview only.
Expand description

Represents the source of markdown content.

This enum provides a unified interface for working with markdown content that can come from either a static string or a file on disk.

Variants§

§

String(String)

Static string content (no auto-reload support).

§

File

File-based content with auto-reload support.

Fields

§path: PathBuf

Path to the markdown file.

§content: String

Cached content from the file.

Implementations§

Source§

impl MarkdownSource

Source

pub fn from_file(path: impl AsRef<Path>) -> Result<MarkdownSource, Error>

Create a new MarkdownSource from a file path.

Reads the file content immediately and caches it.

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

Returns an io::Error if the file cannot be read.

Source§

impl MarkdownSource

Constructor for creating a MarkdownSource from a string.

Source

pub fn from_string(s: impl Into<String>) -> MarkdownSource

Create a new MarkdownSource from a string.

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

impl MarkdownSource

Method to get the content of a MarkdownSource.

Source

pub fn content(&self) -> &str

Get the current content of the markdown source.

For string sources, this returns the original string. For file sources, this returns the cached content.

Source§

impl MarkdownSource

Method to check if a MarkdownSource is file-based.

Source

pub fn is_file(&self) -> bool

Check if this source is file-based.

Source§

impl MarkdownSource

Method to check if a MarkdownSource is string-based.

Source

pub fn is_string(&self) -> bool

Check if this source is string-based.

Source§

impl MarkdownSource

Method to get the file path of a MarkdownSource.

Source

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

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

Returns None for string sources.

Source§

impl MarkdownSource

Method to reload content from a file.

Source

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

Reload the content from the file.

For string sources, this is a no-op and returns Ok(false). For file sources, this re-reads the file and returns Ok(true) if the content has changed.

§Errors

Returns an io::Error if the file cannot be read.

Source§

impl MarkdownSource

Method to set content directly on a MarkdownSource.

Source

pub fn set_content(&mut self, new_content: impl Into<String>) -> bool

Set the content directly (for string sources).

This is useful for updating string-based sources programmatically. For file sources, this updates the cached content but does not write to disk.

Returns true if the content was changed.

Trait Implementations§

Source§

impl Clone for MarkdownSource

Source§

fn clone(&self) -> MarkdownSource

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 MarkdownSource

Source§

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

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

impl Default for MarkdownSource

Default trait implementation for MarkdownSource.

Source§

fn default() -> MarkdownSource

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

impl From<&str> for MarkdownSource

From<&str> trait implementation for MarkdownSource.

Source§

fn from(s: &str) -> MarkdownSource

Converts to this type from the input type.
Source§

impl From<String> for MarkdownSource

From trait implementation for MarkdownSource.

Source§

fn from(s: String) -> MarkdownSource

Converts to this type from the input type.

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