+
Skip to content

break a lot of stuff to try and see what needs to be done for no_std #900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: fix/no-std
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 113 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ categories = ["web-programming::http-client"]
edition = "2018"
exclude = ["/cargo_deny.sh", "/deny.toml", "/test.sh"]


# MSRV
rust-version = "1.71.1"
rust-version = "1.83.0"

[package.metadata.docs.rs]
features = ["rustls", "platform-verifier", "native-tls", "socks-proxy", "cookies", "gzip", "brotli", "charset", "json", "_test"]

[features]
#default = ["rustls", "gzip", "json", "std"]
default = ["rustls", "gzip", "json"]
default = ["rustls", "json"]
rustls = ["dep:rustls", "_tls", "dep:webpki-roots"]
platform-verifier = ["dep:rustls-platform-verifier"]
native-tls = ["dep:native-tls", "dep:der", "_tls", "dep:webpki-root-certs"]
Expand Down Expand Up @@ -75,6 +74,11 @@ encoding_rs = { version = "0.8.34", optional = true }
serde = { version = "1.0.204", optional = true, default-features = false, features = ["std"] }
serde_json = { version = "1.0.120", optional = true, default-features = false, features = ["std"] }

# TODO: no_std?
spin = "0.9.8"
web-time = "1.1.0"
no_std_io = "0.6.0"

[build-dependencies]
cc = "1.0.106"

Expand All @@ -84,7 +88,6 @@ auto-args = "0.3.0"
serde = { version = "1.0.204", features = ["std", "derive"] }
assert_no_alloc = "1.1.2"


[[example]]
name = "cureq"
required-features = ["rustls", "native-tls", "socks-proxy", "cookies", "gzip", "brotli", "charset"]
6 changes: 2 additions & 4 deletions src/agent.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::convert::TryFrom;
use std::fmt::Debug;
use std::sync::Arc;

use alloc::sync::Arc;
use http::{Method, Request, Response, Uri};
use core::convert::TryFrom;

use crate::body::Body;
use crate::config::typestate::{AgentScope, HttpCrateScope};
Expand Down
2 changes: 0 additions & 2 deletions src/body/brotli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::io;

use brotli_decompressor::Decompressor;

use crate::Error;
Expand Down
8 changes: 4 additions & 4 deletions src/body/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::io::{self, Cursor};
use std::sync::Arc;
use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec};

use ureq_proto::BodyMode;

Expand Down Expand Up @@ -112,14 +111,15 @@ impl BodyBuilder {
let len = self.limit.unwrap_or(data.len() as u64);
self.info.body_mode = BodyMode::LengthDelimited(len);

self.reader(Cursor::new(data))
//self.reader(Cursor::new(data))
todo!()
}

/// Creates a body from a streaming reader.
///
/// The reader can be limited by using `.limit()` or that the reader
/// reaches the end.
pub fn reader(self, data: impl io::Read + Send + Sync + 'static) -> Body {
pub fn reader(self, data: impl no_std_io::io::Read + Send + Sync + 'static) -> Body {
Body {
source: BodyDataSource::Reader(Box::new(data)),
info: Arc::new(self.info),
Expand Down
2 changes: 0 additions & 2 deletions src/body/charset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use encoding_rs::{Decoder, Encoder, Encoding};
use std::fmt;
use std::io::{self, BufRead, BufReader};

use crate::util::ConsumeBuf;

Expand Down
4 changes: 2 additions & 2 deletions src/body/gzip.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io;
use no_std_io::io;

use flate2::read::MultiGzDecoder;

Expand Down Expand Up @@ -66,4 +66,4 @@ mod test {

assert_eq!(agent.pool_count(), 1);
}
}
}
2 changes: 1 addition & 1 deletion src/body/limit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io;
use no_std_io::io;

use crate::Error;

Expand Down
6 changes: 4 additions & 2 deletions src/body/lossy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io;
use no_std_io::io;

use utf8::DecodeError;

Expand Down Expand Up @@ -99,7 +99,9 @@ impl<R: io::Read> io::Read for LossyUtf8Reader<R> {

#[cfg(test)]
mod test {
use std::io::Read;
use no_std_io::io;

use alloc::string::String;

use super::*;

Expand Down
12 changes: 7 additions & 5 deletions src/body/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::fmt;
use std::io;
use std::sync::Arc;
use no_std_io::io;
use core::fmt;

use alloc::boxed::Box;
use alloc::string::{String, ToString};
use alloc::sync::Arc;

use alloc::vec::Vec;
pub use build::BodyBuilder;
use ureq_proto::BodyMode;

Expand Down Expand Up @@ -392,7 +396,6 @@ impl<'a> BodyWithConfig<'a> {

/// Read into string.
pub fn read_to_string(self) -> Result<String, Error> {
use std::io::Read;
let mut reader = self.do_build();
let mut buf = String::new();
reader.read_to_string(&mut buf)?;
Expand All @@ -401,7 +404,6 @@ impl<'a> BodyWithConfig<'a> {

/// Read into vector.
pub fn read_to_vec(self) -> Result<Vec<u8>, Error> {
use std::io::Read;
let mut reader = self.do_build();
let mut buf = Vec::new();
reader.read_to_end(&mut buf)?;
Expand Down
9 changes: 5 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Agent configuration

use std::fmt;
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
use core::net::SocketAddr;
use core::time::Duration;

use alloc::fmt;
use alloc::string::String;
use alloc::sync::Arc;
use http::Uri;

use crate::http;
Expand Down
5 changes: 1 addition & 4 deletions src/cookies.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::borrow::Cow;
use std::fmt;
use std::sync::{Mutex, MutexGuard};

use no_std_io::io;
use cookie_store::CookieStore;
use http::Uri;

Expand Down
7 changes: 5 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{fmt, io};
use alloc::fmt;
use alloc::string::String;
use no_std_io::io;

use crate::http;
use crate::Timeout;
Expand Down Expand Up @@ -139,6 +141,7 @@ pub enum Error {
BodyStalled,
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}

impl Error {
Expand Down Expand Up @@ -309,7 +312,7 @@ mod test {
#[test]
fn ensure_error_size() {
// This is platform dependent, so we can't be too strict or precise.
let size = std::mem::size_of::<Error>();
let size = core::mem::size_of::<Error>();
assert!(size < 100); // 40 on Macbook M1
}
}
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载