aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-06-10 03:09:02 +0000
committerFuwn <[email protected]>2022-06-10 03:09:02 +0000
commit3a2ae66674be6b7b375f79a33a3147b12e398484 (patch)
treeca563ac24d9dbf89e4f96ca5c4cfe9bb4db9b661
parentfeat(meta): mutable access to meta for construction (diff)
downloadgerm-3a2ae66674be6b7b375f79a33a3147b12e398484.tar.xz
germ-3a2ae66674be6b7b375f79a33a3147b12e398484.zip
docs(meta): document Meta methods
-rw-r--r--src/meta.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/meta.rs b/src/meta.rs
index 2aaa543..e08c593 100644
--- a/src/meta.rs
+++ b/src/meta.rs
@@ -28,6 +28,17 @@ pub struct Meta {
parameters: HashMap<String, String>,
}
impl ToString for Meta {
+ /// Convert a `Meta` into a `String`
+ ///
+ /// # Example
+ /// ```rust
+ /// let original_string = "text/gemini; hi=2; hi2=string=2";
+ ///
+ /// assert_eq!(
+ /// germ::meta::Meta::from_string(original_string).to_string(),
+ /// original_string
+ /// );
+ /// ```
fn to_string(&self) -> String {
format!("{}{}", self.mime, {
let mut parameters = self
@@ -47,9 +58,26 @@ impl ToString for Meta {
}
}
impl Meta {
+ /// Create a new `Meta`
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// let mut meta = germ::meta::Meta::new();
+ /// ```
#[must_use]
pub fn new() -> Self { Self::default() }
+ /// Create a `Meta` from a string
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// assert_eq!(
+ /// germ::meta::Meta::from_string("text/gemini; hi=2; hi2=string=2").mime(),
+ /// "text/gemini",
+ /// );
+ /// ```
#[must_use]
pub fn from_string(meta: &str) -> Self {
let mut metas = meta.split(';');
@@ -73,16 +101,60 @@ impl Meta {
}
}
+ /// Obtain non-mutable access to the mime of the `Meta`
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// assert_eq!(
+ /// germ::meta::Meta::from_string("text/gemini; hi=2; hi2=string=2").mime(),
+ /// "text/gemini",
+ /// );
+ /// ```
#[must_use]
pub fn mime(&self) -> &str { &self.mime }
+ /// Obtain mutable access to the mime of the `Meta`
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// let mut meta = germ::meta::Meta::new();
+ ///
+ /// *meta.mime_mut() = "text/gemini".to_string();
+ /// ```
pub fn mime_mut(&mut self) -> &mut String { &mut self.mime }
+ /// Obtain non-mutable access to the parameters of the `Meta`
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// assert_eq!(
+ /// germ::meta::Meta::from_string("text/gemini; hi=2; hi2=string=2")
+ /// .parameters()
+ /// .get("hi2"),
+ /// Some(&"string=2".to_string()),
+ /// );
+ /// ```
#[must_use]
pub const fn parameters(&self) -> &HashMap<String, String> {
&self.parameters
}
+ /// Obtain mutable access to the parameters of the `Meta`
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// let mut meta = germ::meta::Meta::new();
+ /// let mut parameters = std::collections::HashMap::new();
+ ///
+ /// parameters.insert("hi".to_string(), "2".to_string());
+ /// parameters.insert("hi2".to_string(), "string=2".to_string());
+ ///
+ /// *meta.parameters_mut() = parameters;
+ /// ```
pub fn parameters_mut(&mut self) -> &mut HashMap<String, String> {
&mut self.parameters
}