Skip to content

Commit 0741039

Browse files
committed
Support sidevm runtime
1 parent 65ad5cf commit 0741039

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lib/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ license = "MIT"
1717
[features]
1818
openssl = ["hyper-tls"]
1919
rustls = ["hyper-rustls"]
20-
default = ["openssl"]
20+
tokio-runtime = ["tokio"]
21+
sidevm-runtime = ["sidevm"]
22+
default = ["openssl", "tokio-runtime"]
23+
2124
[dependencies]
2225
bytes = "1.0.1"
23-
tokio = { version = "1.2", features = ["fs", "rt"]}
26+
tokio = { version = "1.2", features = ["fs", "rt"], optional = true }
27+
sidevm = { version = "0.1", optional = true }
2428

2529
tracing = "0.1.23"
2630
tracing-futures = "0.2"
@@ -32,6 +36,7 @@ hyper = { version = "0.14", features = ["client", "http1"] }
3236
hyper-tls = { version = "0.5", optional = true }
3337
futures = "0.3"
3438
hyper-rustls = { version = "0.22", optional = true }
39+
3540
[dev-dependencies]
3641
tracing-subscriber = "0.2.15"
3742
tokio = { version = "1.2", features = ["macros", "time", "fs", "rt-multi-thread"] }

lib/src/api.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use std::sync::{
55
use std::time::Duration;
66

77
use futures::{Future, FutureExt};
8-
use tokio::time::timeout;
8+
#[cfg(feature = "sidevm-runtime")]
9+
use sidevm::{spawn, time::timeout};
10+
#[cfg(feature = "tokio-runtime")]
11+
use tokio::{spawn, time::timeout};
912
use tracing_futures::Instrument;
1013

1114
use telegram_bot_raw::{HttpRequest, Request, ResponseType};
@@ -94,7 +97,7 @@ impl Api {
9497
pub fn spawn<Req: Request>(&self, request: Req) {
9598
let api = self.clone();
9699
if let Ok(request) = request.serialize() {
97-
tokio::spawn(async move {
100+
spawn(async move {
98101
let _ = api.send_http_request::<Req::Response>(request).await;
99102
});
100103
}

lib/src/connector/hyper.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::io::{Cursor, Read};
2+
#[cfg(feature = "tokio-runtime")]
23
use std::path::Path;
34
use std::pin::Pin;
45
use std::str::FromStr;
@@ -76,6 +77,11 @@ impl<C: Connect + std::fmt::Debug + 'static + Clone + Send + Sync> Connector for
7677
MultipartValue::Text(text) => {
7778
fields.push((key, MultipartTemporaryValue::Text(text)))
7879
}
80+
#[cfg(feature = "sidevm-runtime")]
81+
MultipartValue::Path { .. } => {
82+
return Err(ErrorKind::InvalidMultipartFilename.into());
83+
}
84+
#[cfg(feature = "tokio-runtime")]
7985
MultipartValue::Path { file_name, path } => {
8086
let file_name = file_name
8187
.or_else(|| {
@@ -157,6 +163,7 @@ impl<C: Connect + std::fmt::Debug + 'static + Clone + Send + Sync> Connector for
157163
}
158164
}
159165

166+
#[cfg(feature = "tokio-runtime")]
160167
pub fn default_connector() -> Result<Box<dyn Connector>, Error> {
161168
#[cfg(feature = "rustls")]
162169
let connector = HttpsConnector::with_native_roots();
@@ -168,3 +175,12 @@ pub fn default_connector() -> Result<Box<dyn Connector>, Error> {
168175
Client::builder().build(connector),
169176
)))
170177
}
178+
179+
#[cfg(feature = "sidevm-runtime")]
180+
pub fn default_connector() -> Result<Box<dyn Connector>, Error> {
181+
Ok(Box::new(HyperConnector::new(
182+
Client::builder()
183+
.executor(sidevm::exec::HyperExecutor)
184+
.build(sidevm::net::HttpConnector),
185+
)))
186+
}

0 commit comments

Comments
 (0)