Skip to content

Commit eac173c

Browse files
committed
Fixing the interface
1 parent f705eb6 commit eac173c

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

mocktail/src/form.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@ pub struct FormBody {
77
}
88

99
impl FormBody {
10+
/// Creates a new form.
11+
pub fn new() -> Self {
12+
Self { fields: Vec::new() }
13+
}
14+
1015
/// Creates an empty form.
1116
pub fn empty() -> Self {
1217
Self::default()
1318
}
1419

1520
/// Adds a field to the form.
16-
pub fn add_field(&mut self, name: impl Into<String>, value: impl Into<String>) {
17-
self.fields.push((name.into(), value.into()));
21+
pub fn field(self, name: impl Into<String>, value: impl Into<String>) -> Self {
22+
let mut fields = self.fields;
23+
24+
fields.push((name.into(), value.into()));
25+
26+
Self { fields }
1827
}
1928

2029
/// Converts the form body to a URL-encoded string.

mocktail/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![doc = include_str!("../README.md")]
22
pub mod body;
3+
pub mod form;
34
mod headers;
45
pub use headers::Headers;
56
pub mod matchers;
@@ -18,6 +19,7 @@ pub use status::{Code, StatusCode};
1819
pub mod prelude {
1920
pub use crate::{
2021
body::Body,
22+
form::FormBody,
2123
headers::Headers,
2224
matchers::*,
2325
mock::Mock,
@@ -30,7 +32,6 @@ pub mod prelude {
3032
}
3133
mod ext;
3234
mod service;
33-
mod form;
3435

3536
/// Represents errors that can occur while serving mocks.
3637
#[derive(thiserror::Error, Debug)]

mocktail/src/mock_builder/when.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl When {
6767
}
6868

6969
/// Form Body.
70-
pub fn form(self, body: FormBody) -> Self {
71-
self.push(matchers::form(body));
70+
pub fn form(self, form_body: FormBody) -> Self {
71+
self.push(matchers::form(form_body));
7272
self
7373
}
7474

0 commit comments

Comments
 (0)