wasi_net/reqwest/
multipart.rs1use std::borrow::Cow;
2use urlencoding::encode;
3
4pub struct Form {
5 parts: Vec<(String, String)>,
6}
7
8impl Default for Form {
9 fn default() -> Self {
10 Self::new()
11 }
12}
13
14impl Form {
15 pub fn new() -> Form {
17 Form { parts: Vec::new() }
18 }
19
20 pub fn text<T, U>(mut self, name: T, value: U) -> Form
21 where
22 T: Into<Cow<'static, str>>,
23 U: Into<Cow<'static, str>>,
24 {
25 self.parts
26 .push((name.into().to_string(), value.into().to_string()));
27 self
28 }
29
30 pub fn to_string(&self) -> String {
31 let mut ret = String::new();
32 for n in 0..self.parts.len() {
33 let first = n == 0;
34 if first == false {
35 ret += "&";
36 }
37 let (name, value) = &self.parts[n];
38 ret += &encode(name.as_str());
39 ret += "=";
40 ret += &encode(value.as_str());
41 }
42 ret
43 }
44}