Skip to content

Commit a9a9a63

Browse files
committed
no_std + alloc crate
1 parent e7a535a commit a9a9a63

File tree

15 files changed

+98
-43
lines changed

15 files changed

+98
-43
lines changed

src/body.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::fmt;
2-
use std::io::Write;
1+
use alloc::string::ToString;
2+
use core::fmt;
3+
use core::fmt::Write;
34

45
use http::{HeaderName, HeaderValue, Method};
56

src/chunk.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ impl Dechunker {
178178

179179
#[cfg(test)]
180180
mod test {
181+
use alloc::string::String;
182+
181183
use super::*;
182184

183185
#[test]

src/client/amended.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::mem;
1+
use alloc::string::ToString;
2+
use core::mem;
23

34
use http::{HeaderMap, HeaderName, HeaderValue, Method, Request, Uri, Version};
45
use url::Url;
@@ -143,7 +144,7 @@ impl<Body> AmendedRequest<Body> {
143144
}
144145

145146
#[cfg(test)]
146-
pub fn headers_vec(&self) -> Vec<(&str, &str)> {
147+
pub fn headers_vec(&self) -> alloc::vec::Vec<(&str, &str)> {
147148
self.headers()
148149
// unwrap here is ok because the tests using this method should
149150
// only use header values representable as utf-8.

src/client/call.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! A single request-response. No redirection or other logic.
22
3-
use std::fmt;
4-
use std::io::Write;
5-
use std::marker::PhantomData;
3+
use alloc::string::ToString;
4+
use core::fmt;
5+
use core::fmt::Write;
6+
use core::marker::PhantomData;
67

78
use http::{HeaderName, HeaderValue, Method, Request, Response, StatusCode, Version};
89

@@ -643,7 +644,8 @@ impl fmt::Debug for Phase {
643644
mod test {
644645
use super::*;
645646

646-
use std::str;
647+
use alloc::vec;
648+
use core::str;
647649

648650
use http::{Method, Request};
649651

src/client/flow.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//! A sequence of calls, such as following redirects.
22
3-
use std::fmt;
4-
use std::marker::PhantomData;
3+
use alloc::string::String;
4+
use alloc::string::ToString;
5+
use core::fmt;
6+
use core::marker::PhantomData;
57

68
use http::uri::Scheme;
7-
use http::{
8-
HeaderMap, HeaderName, HeaderValue, Method, Request, Response, StatusCode, Uri, Version,
9-
};
9+
use http::{HeaderMap, HeaderName, HeaderValue, Method, Request};
10+
use http::{Response, StatusCode, Uri, Version};
1011

1112
use crate::body::calculate_max_input;
1213
use crate::ext::{HeaderIterExt, MethodExt, StatusExt};

src/client/holder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::mem;
1+
use core::mem;
22

33
use http::Request;
44

src/client/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ trait TestSliceExt {
2222

2323
impl TestSliceExt for [u8] {
2424
fn as_str(&self) -> &str {
25-
std::str::from_utf8(self).unwrap()
25+
core::str::from_utf8(self).unwrap()
2626
}
2727
}

src/client/test/scenario.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
use std::io::Write;
2-
use std::marker::PhantomData;
1+
use core::fmt::Write;
2+
// use std::io::Write;
3+
use core::marker::PhantomData;
4+
5+
// use std::prelude::rust_2021::*;
6+
// use std::vec;
7+
8+
use alloc::string::String;
9+
use alloc::string::ToString;
10+
use alloc::vec;
11+
use alloc::vec::Vec;
312

413
use http::{Method, Request, Response, StatusCode};
514

@@ -8,6 +17,7 @@ use crate::client::flow::state::{
817
};
918
use crate::client::flow::{Await100Result, Flow, SendRequestResult};
1019
use crate::client::flow::{RecvBodyResult, RecvResponseResult};
20+
use crate::util::Writer;
1121

1222
pub struct Scenario {
1323
request: Request<()>,
@@ -176,12 +186,13 @@ impl Scenario {
176186
}
177187

178188
pub fn write_response(r: &Response<()>) -> Vec<u8> {
179-
let mut input = Vec::<u8>::new();
189+
let mut input = vec![0; 1024];
190+
let mut w = Writer::new(&mut input);
180191

181192
let s = r.status();
182193

183194
write!(
184-
&mut input,
195+
&mut w,
185196
"{:?} {} {}\r\n",
186197
r.version(),
187198
s.as_u16(),
@@ -190,10 +201,15 @@ pub fn write_response(r: &Response<()>) -> Vec<u8> {
190201
.unwrap();
191202

192203
for (k, v) in r.headers().iter() {
193-
write!(&mut input, "{}: {}\r\n", k.as_str(), v.to_str().unwrap()).unwrap();
204+
write!(&mut w, "{}: {}\r\n", k.as_str(), v.to_str().unwrap()).unwrap();
194205
}
195206

196-
write!(&mut input, "\r\n").unwrap();
207+
write!(&mut w, "\r\n").unwrap();
208+
209+
let len = w.len();
210+
211+
drop(w);
212+
input.truncate(len);
197213

198214
input
199215
}

src/client/test/state_recv_body.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use alloc::vec;
2+
13
use http::Response;
24

35
use crate::client::flow::CloseReason;

src/client/test/state_redirect.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use alloc::string::ToString;
2+
use alloc::vec;
3+
14
use http::{Method, Response, StatusCode};
25

36
use crate::client::flow::RedirectAuthHeaders;

0 commit comments

Comments
 (0)