Struct tpnote_lib::front_matter::FrontMatter
source · [−]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
sourceimpl FrontMatter
impl FrontMatter
sourcepub fn assert_compulsory_field(&self) -> Result<(), NoteError>
pub fn assert_compulsory_field(&self) -> Result<(), NoteError>
Checks if the front matter contains a field variable with the name defined in the configuration file: as: “compulsory_header_field”.
sourcepub fn assert_not_empty(&self) -> Result<(), NoteError>
pub fn assert_not_empty(&self) -> Result<(), NoteError>
Are any variables registerd?
Methods from Deref<Target = Map<String, Value>>
sourcepub fn get<Q>(&self, key: &Q) -> Option<&Value>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn get<Q>(&self, key: &Q) -> Option<&Value>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
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.
sourcepub fn contains_key<Q>(&self, key: &Q) -> boolwhere
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn contains_key<Q>(&self, key: &Q) -> boolwhere
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
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.
sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
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.
sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
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.
sourcepub fn insert(&mut self, k: String, v: Value) -> Option<Value>
pub fn insert(&mut self, k: String, v: Value) -> Option<Value>
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.
sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<Value>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
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.
sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
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.
sourcepub fn append(&mut self, other: &mut Map<String, Value>)
pub fn append(&mut self, other: &mut Map<String, Value>)
Moves all elements from other into self, leaving other empty.
sourcepub fn entry<S>(&mut self, key: S) -> Entry<'_>where
S: Into<String>,
pub fn entry<S>(&mut self, key: S) -> Entry<'_>where
S: Into<String>,
Gets the given key’s corresponding entry in the map for in-place manipulation.
sourcepub fn values_mut(&mut self) -> ValuesMut<'_>
pub fn values_mut(&mut self) -> ValuesMut<'_>
Gets an iterator over mutable values of the map.
Trait Implementations
sourceimpl Debug for FrontMatter
impl Debug for FrontMatter
sourceimpl Deref for FrontMatter
impl Deref for FrontMatter
Auto-dereference for convenient access to tera::Map.
sourceimpl DerefMut for FrontMatter
impl DerefMut for FrontMatter
Auto-dereference for convenient access to tera::Map.
sourceimpl PartialEq<FrontMatter> for FrontMatter
impl PartialEq<FrontMatter> for FrontMatter
sourcefn eq(&self, other: &FrontMatter) -> bool
fn eq(&self, other: &FrontMatter) -> bool
sourceimpl TryFrom<&Content> for FrontMatter
impl TryFrom<&Content> for FrontMatter
sourcefn try_from(content: &Content) -> Result<FrontMatter, NoteError>
fn try_from(content: &Content) -> Result<FrontMatter, NoteError>
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")));sourceimpl TryFrom<&str> for FrontMatter
impl TryFrom<&str> for FrontMatter
impl Eq for FrontMatter
impl StructuralEq for FrontMatter
impl StructuralPartialEq for FrontMatter
Auto Trait Implementations
impl RefUnwindSafe for FrontMatter
impl Send for FrontMatter
impl Sync for FrontMatter
impl Unpin for FrontMatter
impl UnwindSafe for FrontMatter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.