frontmatter_gen::types

Struct Frontmatter

Source
pub struct Frontmatter(pub HashMap<String, Value>);
Expand description

Represents the frontmatter, a collection of key-value pairs.

Tuple Fields§

§0: HashMap<String, Value>

Implementations§

Source§

impl Frontmatter

Source

pub fn new() -> Self

Creates a new, empty frontmatter.

§Returns

A new Frontmatter instance with no key-value pairs.

§Examples
use frontmatter_gen::Frontmatter;

let fm = Frontmatter::new();
assert!(fm.is_empty());
Source

pub fn insert(&mut self, key: String, value: Value) -> Option<Value>

Inserts a key-value pair into the frontmatter.

§Arguments
  • key - The key for the entry.
  • value - The value associated with the key.
§Returns

An option containing the old value if it was replaced.

§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm = Frontmatter::new();
assert_eq!(fm.insert("key".to_string(), Value::String("value".to_string())), None);
assert_eq!(fm.insert("key".to_string(), Value::Number(42.0)), Some(Value::String("value".to_string())));
Source

pub fn get(&self, key: &str) -> Option<&Value>

Retrieves a reference to a value associated with a key.

§Arguments
  • key - The key to look up.
§Returns

An option containing a reference to the value if the key exists.

§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm = Frontmatter::new();
fm.insert("key".to_string(), Value::String("value".to_string()));
assert_eq!(fm.get("key"), Some(&Value::String("value".to_string())));
assert_eq!(fm.get("nonexistent"), None);
Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut Value>

Retrieves a mutable reference to a value associated with a key.

§Arguments
  • key - The key to look up.
§Returns

An option containing a mutable reference to the value if the key exists.

§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm = Frontmatter::new();
fm.insert("key".to_string(), Value::String("value".to_string()));
if let Some(value) = fm.get_mut("key") {
    *value = Value::Number(42.0);
}
assert_eq!(fm.get("key"), Some(&Value::Number(42.0)));
Source

pub fn remove(&mut self, key: &str) -> Option<Value>

Removes a key-value pair from the frontmatter.

§Arguments
  • key - The key to remove.
§Returns

An option containing the removed value if the key existed.

§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm = Frontmatter::new();
fm.insert("key".to_string(), Value::String("value".to_string()));
assert_eq!(fm.remove("key"), Some(Value::String("value".to_string())));
assert_eq!(fm.remove("key"), None);
Source

pub fn contains_key(&self, key: &str) -> bool

Checks if the frontmatter contains a given key.

§Arguments
  • key - The key to check for.
§Returns

true if the key exists in the frontmatter, false otherwise.

§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm = Frontmatter::new();
fm.insert("key".to_string(), Value::String("value".to_string()));
assert!(fm.contains_key("key"));
assert!(!fm.contains_key("nonexistent"));
Source

pub fn len(&self) -> usize

Returns the number of entries in the frontmatter.

§Returns

The number of key-value pairs in the frontmatter.

§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm = Frontmatter::new();
assert_eq!(fm.len(), 0);
fm.insert("key".to_string(), Value::String("value".to_string()));
assert_eq!(fm.len(), 1);
Source

pub fn is_empty(&self) -> bool

Checks if the frontmatter is empty.

§Returns

true if the frontmatter contains no key-value pairs, false otherwise.

§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm = Frontmatter::new();
assert!(fm.is_empty());
fm.insert("key".to_string(), Value::String("value".to_string()));
assert!(!fm.is_empty());
Source

pub fn iter(&self) -> Iter<'_, String, Value>

Returns an iterator over the key-value pairs of the frontmatter.

§Returns

An iterator over references to the key-value pairs.

§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm = Frontmatter::new();
fm.insert("key1".to_string(), Value::String("value1".to_string()));
fm.insert("key2".to_string(), Value::Number(42.0));

for (key, value) in fm.iter() {
    println!("{}: {:?}", key, value);
}
Source

pub fn iter_mut(&mut self) -> IterMut<'_, String, Value>

Returns a mutable iterator over the key-value pairs of the frontmatter.

§Returns

A mutable iterator over references to the key-value pairs.

§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm = Frontmatter::new();
fm.insert("key1".to_string(), Value::String("value1".to_string()));
fm.insert("key2".to_string(), Value::Number(42.0));

for (_, value) in fm.iter_mut() {
    if let Value::Number(n) = value {
        *n += 1.0;
    }
}

assert_eq!(fm.get("key2"), Some(&Value::Number(43.0)));
Source

pub fn merge(&mut self, other: Frontmatter)

Merges another frontmatter into this one. If a key exists, it will be overwritten.

§Arguments
  • other - The frontmatter to merge into this one.
§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm1 = Frontmatter::new();
fm1.insert("key1".to_string(), Value::String("value1".to_string()));

let mut fm2 = Frontmatter::new();
fm2.insert("key2".to_string(), Value::Number(42.0));

fm1.merge(fm2);
assert_eq!(fm1.len(), 2);
assert_eq!(fm1.get("key2"), Some(&Value::Number(42.0)));
Source

pub fn is_null(&self, key: &str) -> bool

Checks if a given key exists and its value is null.

§Arguments
  • key - The key to check.
§Returns

true if the key exists and its value is null, false otherwise.

§Examples
use frontmatter_gen::{Frontmatter, Value};

let mut fm = Frontmatter::new();
fm.insert("null_key".to_string(), Value::Null);
fm.insert("non_null_key".to_string(), Value::String("value".to_string()));

assert!(fm.is_null("null_key"));
assert!(!fm.is_null("non_null_key"));
assert!(!fm.is_null("nonexistent_key"));
Source

pub fn clear(&mut self)

Clears the frontmatter while preserving allocated capacity

Source

pub fn capacity(&self) -> usize

Returns the current capacity of the underlying HashMap

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements

Trait Implementations§

Source§

impl Clone for Frontmatter

Source§

fn clone(&self) -> Frontmatter

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 Frontmatter

Source§

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

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

impl Default for Frontmatter

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Frontmatter

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Frontmatter

Implement Display for Frontmatter to allow easy printing with escaped characters.

Source§

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

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

impl FromIterator<(String, Value)> for Frontmatter

Implement FromIterator for Frontmatter to create a frontmatter from an iterator.

Source§

fn from_iter<I: IntoIterator<Item = (String, Value)>>(iter: I) -> Self

Creates a Frontmatter from an iterator of key-value pairs.

§Arguments
  • iter - An iterator of key-value pairs where the key is a String and the value is a Value.
§Returns

A Frontmatter containing the key-value pairs from the iterator.

§Examples
use frontmatter_gen::{Frontmatter, Value};
use std::iter::FromIterator;

let pairs = vec![
    ("key1".to_string(), Value::String("value1".to_string())),
    ("key2".to_string(), Value::Number(42.0)),
];

let fm = Frontmatter::from_iter(pairs);
assert_eq!(fm.len(), 2);
assert_eq!(fm.get("key1"), Some(&Value::String("value1".to_string())));
assert_eq!(fm.get("key2"), Some(&Value::Number(42.0)));
Source§

impl IntoIterator for Frontmatter

Implement IntoIterator for Frontmatter to allow idiomatic iteration.

Source§

type Item = (String, Value)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<String, Value>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Frontmatter

Source§

fn eq(&self, other: &Frontmatter) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Frontmatter

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Frontmatter

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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T