Skip to content

Commit 9fb31d1

Browse files
committed
rename methods again
1 parent ea3fb64 commit 9fb31d1

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/chunked/encoder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ impl ChunkedEncoder {
7272
buf: &mut [u8],
7373
) -> Poll<io::Result<usize>> {
7474
self.bytes_written = 0;
75-
let res = self.dispatch(res, cx, buf);
75+
let res = self.run(res, cx, buf);
7676
log::trace!("ChunkedEncoder {} bytes written", self.bytes_written);
7777
res
7878
}
7979

8080
/// Execute the right method for the current state.
81-
fn dispatch(
81+
fn run(
8282
&mut self,
8383
res: &mut Response,
8484
cx: &mut Context<'_>,
8585
buf: &mut [u8],
8686
) -> Poll<io::Result<usize>> {
8787
match self.state {
88-
State::Start => self.set_state(State::EncodeChunks, res, cx, buf),
88+
State::Start => self.dispatch(State::EncodeChunks, res, cx, buf),
8989
State::EncodeChunks => self.encode_chunks(res, cx, buf),
9090
State::EndOfChunks => self.encode_chunks_eos(res, cx, buf),
9191
State::ReceiveTrailers => self.receive_trailers(res, cx, buf),
@@ -96,7 +96,7 @@ impl ChunkedEncoder {
9696
}
9797

9898
/// Switch the internal state to a new state.
99-
fn set_state(
99+
fn dispatch(
100100
&mut self,
101101
state: State,
102102
res: &mut Response,
@@ -118,7 +118,7 @@ impl ChunkedEncoder {
118118
}
119119

120120
self.state = state;
121-
self.dispatch(res, cx, buf)
121+
self.run(res, cx, buf)
122122
}
123123

124124
/// Stream out data using chunked encoding.
@@ -142,7 +142,7 @@ impl ChunkedEncoder {
142142
// If the stream doesn't have any more bytes left to read we're done
143143
// sending chunks and it's time to move on.
144144
if src.len() == 0 {
145-
return self.set_state(State::EndOfChunks, res, cx, buf);
145+
return self.dispatch(State::EndOfChunks, res, cx, buf);
146146
}
147147

148148
// Each chunk is prefixed with the length of the data in hex, then a
@@ -209,7 +209,7 @@ impl ChunkedEncoder {
209209
buf[idx + 2] = LF;
210210
self.bytes_written += 1 + CRLF_LEN;
211211

212-
self.set_state(State::ReceiveTrailers, res, cx, buf)
212+
self.dispatch(State::ReceiveTrailers, res, cx, buf)
213213
}
214214

215215
/// Receive trailers sent to the response, and store them in an internal
@@ -221,7 +221,7 @@ impl ChunkedEncoder {
221221
buf: &mut [u8],
222222
) -> Poll<io::Result<usize>> {
223223
// TODO: actually wait for trailers to be received.
224-
self.set_state(State::EncodeTrailers, res, cx, buf)
224+
self.dispatch(State::EncodeTrailers, res, cx, buf)
225225
}
226226

227227
/// Send trailers to the buffer.
@@ -232,7 +232,7 @@ impl ChunkedEncoder {
232232
buf: &mut [u8],
233233
) -> Poll<io::Result<usize>> {
234234
// TODO: actually encode trailers here.
235-
self.set_state(State::EndOfStream, res, cx, buf)
235+
self.dispatch(State::EndOfStream, res, cx, buf)
236236
}
237237

238238
/// Encode the end of the stream.
@@ -247,6 +247,6 @@ impl ChunkedEncoder {
247247
buf[idx] = CR;
248248
buf[idx + 1] = LF;
249249
self.bytes_written += CRLF_LEN;
250-
self.set_state(State::End, res, cx, buf)
250+
self.dispatch(State::End, res, cx, buf)
251251
}
252252
}

src/server/encode.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Read for Encoder {
6060
buf: &mut [u8],
6161
) -> Poll<io::Result<usize>> {
6262
self.bytes_written = 0;
63-
let res = self.dispatch(cx, buf);
63+
let res = self.run(cx, buf);
6464
log::trace!("ServerEncoder {} bytes written", self.bytes_written);
6565
res
6666
}
@@ -83,7 +83,7 @@ impl Encoder {
8383
}
8484

8585
/// Switch the internal state to a new state.
86-
fn set_state(
86+
fn dispatch(
8787
&mut self,
8888
state: State,
8989
cx: &mut Context<'_>,
@@ -103,13 +103,13 @@ impl Encoder {
103103
}
104104

105105
self.state = state;
106-
self.dispatch(cx, buf)
106+
self.run(cx, buf)
107107
}
108108

109109
/// Execute the right method for the current state.
110-
fn dispatch(&mut self, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
110+
fn run(&mut self, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
111111
match self.state {
112-
State::Start => self.set_state(State::ComputeHead, cx, buf),
112+
State::Start => self.dispatch(State::ComputeHead, cx, buf),
113113
State::ComputeHead => self.compute_head(cx, buf),
114114
State::EncodeHead => self.encode_head(cx, buf),
115115
State::EncodeFixedBody => self.encode_fixed_body(cx, buf),
@@ -152,7 +152,7 @@ impl Encoder {
152152

153153
std::io::Write::write_fmt(&mut self.head, format_args!("\r\n"))?;
154154

155-
self.set_state(State::EncodeHead, cx, buf)
155+
self.dispatch(State::EncodeHead, cx, buf)
156156
}
157157

158158
/// Encode the status code + headers.
@@ -173,9 +173,9 @@ impl Encoder {
173173
match self.res.len() {
174174
Some(body_len) => {
175175
self.body_len = body_len;
176-
self.set_state(State::EncodeFixedBody, cx, buf)
176+
self.dispatch(State::EncodeFixedBody, cx, buf)
177177
}
178-
None => self.set_state(State::EncodeChunkedBody, cx, buf),
178+
None => self.dispatch(State::EncodeChunkedBody, cx, buf),
179179
}
180180
} else {
181181
// If we haven't read the entire header it means `buf` isn't
@@ -227,11 +227,11 @@ impl Encoder {
227227

228228
if self.body_len == self.body_bytes_written {
229229
// If we've read the `len` number of bytes, end
230-
self.set_state(State::End, cx, buf)
230+
self.dispatch(State::End, cx, buf)
231231
} else if new_body_bytes_written == 0 {
232232
// If we've reached unexpected EOF, end anyway
233233
// TODO: do something?
234-
self.set_state(State::End, cx, buf)
234+
self.dispatch(State::End, cx, buf)
235235
} else {
236236
// Else continue encoding
237237
self.encode_fixed_body(cx, buf)
@@ -250,7 +250,7 @@ impl Encoder {
250250
Poll::Ready(Ok(read)) => {
251251
self.bytes_written += read;
252252
match self.bytes_written {
253-
0 => self.set_state(State::End, cx, buf),
253+
0 => self.dispatch(State::End, cx, buf),
254254
_ => Poll::Ready(Ok(self.bytes_written)),
255255
}
256256
}

0 commit comments

Comments
 (0)