Adds more builders

This commit is contained in:
2024-11-27 15:11:01 +00:00
parent 326b3919d1
commit db5a01afef
4 changed files with 120 additions and 26 deletions

View File

@@ -1,4 +1,4 @@
use std::{collections::HashMap, str::FromStr};
use std::{collections::HashMap, str::FromStr, vec};
use serde::{Deserialize, Serialize};
@@ -20,6 +20,39 @@ impl Content {
.collect::<String>()
})
}
pub fn builder() -> ContentBuilder {
ContentBuilder::new()
}
}
pub struct ContentBuilder {
content: Content,
}
impl ContentBuilder {
pub fn new() -> Self {
Self {
content: Default::default(),
}
}
pub fn add_part(mut self, part: Part) -> Self {
match &mut self.content.parts {
Some(parts) => parts.push(part),
None => self.content.parts = Some(vec![part]),
}
self
}
pub fn role(mut self, role: Role) -> Self {
self.content.role = Some(role);
self
}
pub fn build(self) -> Content {
self.content
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]