obsidian_export

Struct Context

Source
pub struct Context {
    pub destination: PathBuf,
    pub frontmatter: Frontmatter,
    /* private fields */
}
Expand description

Context holds metadata about a note which is being parsed.

This is used internally to keep track of nesting and help with constructing proper references to other notes.

It is also passed to postprocessors to provide contextual information and allow modification of a note’s frontmatter.

Fields§

§destination: PathBuf

The path where this note will be written to when exported.

Changing this path will result in the note being written to that new path instead, but beware: links will not be updated automatically. If this is changed by a postprocessor, it’s up to that postprocessor to rewrite any existing links to this new path.

§frontmatter: Frontmatter

The Frontmatter for this note. Frontmatter may be modified in-place (see serde_yaml::Mapping for available methods) or replaced entirely.

§Example

Insert foo: bar into a note’s frontmatter:

use obsidian_export::serde_yaml::Value;

let key = Value::String("foo".to_string());

context
    .frontmatter
    .insert(key.clone(), Value::String("bar".to_string()));

Implementations§

Source§

impl Context

Source

pub fn new(src: PathBuf, dest: PathBuf) -> Self

Create a new Context

Source

pub fn from_parent(context: &Self, child: &Path) -> Self

Create a new Context which inherits from a parent Context.

Source

pub fn current_file(&self) -> &PathBuf

Return the path of the file currently being parsed.

Source

pub fn root_file(&self) -> &PathBuf

Return the path of the root file.

Typically this will yield the same element as current_file, but when a note is embedded within another note, this will return the outer-most note.

Source

pub fn note_depth(&self) -> usize

Return the note depth (nesting level) for this context.

Source

pub fn file_tree(&self) -> Vec<PathBuf>

Return the list of files associated with this context.

The first element corresponds to the root file, the final element corresponds to the file which is currently being processed (see also current_file).

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

Returns a copy 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 Context

Source§

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

Formats the value using the given formatter. 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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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> 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> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.