hydrus_api/wrapper/builders/
notes_builder.rs1use crate::api_core::common::FileIdentifier;
2use crate::error::Result;
3use crate::Client;
4use std::collections::HashMap;
5
6pub struct AddNotesBuilder {
8 client: Client,
9 file: FileIdentifier,
10 notes: HashMap<String, String>,
11}
12
13impl AddNotesBuilder {
14 pub fn new(client: Client, file: FileIdentifier) -> Self {
16 Self {
17 client,
18 file,
19 notes: HashMap::new(),
20 }
21 }
22
23 pub fn add_note<S1: ToString, S2: ToString>(mut self, name: S1, note: S2) -> Self {
25 self.notes.insert(name.to_string(), note.to_string());
26
27 self
28 }
29
30 pub fn add_notes<I: IntoIterator<Item = (S1, S2)>, S1: ToString, S2: ToString>(
32 mut self,
33 notes: I,
34 ) -> Self {
35 let notes_iter = notes
36 .into_iter()
37 .map(|(k, v): (S1, S2)| (k.to_string(), v.to_string()));
38 self.notes.extend(notes_iter);
39
40 self
41 }
42
43 pub async fn run(self) -> Result<()> {
45 self.client.set_notes(self.file, self.notes).await
46 }
47}