pub struct FrontMatter(pub Map<String, Value>);
Expand description

Represents the front matter of the note. This is a newtype for tera::Map<String, tera::Value>.

Tuple Fields

0: Map<String, Value>

Implementations

Checks if the front matter contains a field variable with the name defined in the configuration file: as: “compulsory_header_field”.

Are any variables registerd?

Methods from Deref<Target = Map<String, Value>>

Clears the map, removing all values.

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Returns a mutable reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Returns the key-value pair matching the given key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned.

Removes a key from the map, returning the value at the key if the key was previously in the map.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>where
    String: Borrow<Q>,
    Q: Ord + Eq + Hash + ?Sized,

Removes a key from the map, returning the stored key and value if the key was previously in the map.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Moves all elements from other into self, leaving other empty.

Gets the given key’s corresponding entry in the map for in-place manipulation.

Returns the number of elements in the map.

Returns true if the map contains no elements.

Gets an iterator over the entries of the map.

Gets a mutable iterator over the entries of the map.

Gets an iterator over the keys of the map.

Gets an iterator over the values of the map.

Gets an iterator over mutable values of the map.

Retains only the elements specified by the predicate.

In other words, remove all pairs (k, v) such that f(&k, &mut v) returns false.

Trait Implementations

Formats the value using the given formatter. Read more

Auto-dereference for convenient access to tera::Map.

The resulting type after dereferencing.
Dereferences the value.

Auto-dereference for convenient access to tera::Map.

Mutably dereferences the value.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Helper function deserialising the front-matter of the note file.

use tpnote_lib::content::Content;
use tpnote_lib::front_matter::FrontMatter;
use serde_json::json;
// Create existing note.
let raw = "\u{feff}---\ntitle: \"My day\"\nsubtitle: \"Note\"\n---\nBody";
let content = Content::from(raw.to_string());
assert!(!content.is_empty());
assert!(!content.borrow_dependent().header.is_empty());

let front_matter = FrontMatter::try_from(&content).unwrap();
assert_eq!(front_matter.get("title"), Some(&json!("My day")));
assert_eq!(front_matter.get("subtitle"), Some(&json!("Note")));
The type returned in the event of a conversion error.

Helper function deserialising the front-matter of the note file.

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.