Skip to content

Commit 8875fa9

Browse files
committed
Remove dependency actix_rt
1 parent ec76675 commit 8875fa9

19 files changed

+103
-31
lines changed

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ members = [
1111

1212
[dev-dependencies]
1313
actix = "*"
14+
actix-web = "*"
1415
rand = "*"
1516
chrono = "*"
1617
md-5 = "*"
1718
rust_decimal = "*"
1819
bigdecimal = { version="*", features = ["serde"] }
19-
num-bigint = "0.2.6"
2020
flate2 = "*" # Rust语言主要作者alexcrichton开发的一个gzip库
21-
tokio = { version = "*", features = ["full"] }
22-
actix-web = "*"
23-
actix-rt = "*"
21+
tokio = { version = "*", features = ["macros"] }
2422
reqwest = { version = "*", features = ["json"] }
2523
serde = { version = "*", features = ["derive"] }
2624
serde_json = "*"

benches/bigdecimal.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
/*!
2+
BigDecimal占据内存大小和性能都远不如rust_decimal,已弃用
3+
本测试就是为了比较BigDecimal在运算过程中rhs和lhs都要使用指针性能才更好的特点
4+
*/
15
#![feature(test)]
26
extern crate test;
3-
// cargo +nightly bench --bench bigdecimal
47

58
use bigdecimal::{BigDecimal, FromPrimitive};
69
use std::borrow::Borrow;
@@ -198,11 +201,13 @@ fn two_mul_both_ref(bencher: &mut test::Bencher) {
198201
// ========================================
199202

200203
//////////////////// 项目中的last_price比较 ////////////////////
204+
#[cfg(not)]
201205
lazy_static::lazy_static! {
202206
static ref MAX_RATIO: BigDecimal = BigDecimal::from_str("1.1").unwrap();
203207
static ref MIN_RATIO: BigDecimal = BigDecimal::from_str("0.9").unwrap();
204208
}
205209

210+
#[cfg(not)]
206211
#[bench]
207212
#[ignore]
208213
fn last_price_lazy_static_ref(bencher: &mut test::Bencher) {
@@ -215,6 +220,7 @@ fn last_price_lazy_static_ref(bencher: &mut test::Bencher) {
215220
});
216221
}
217222

223+
#[cfg(not)]
218224
#[bench]
219225
#[ignore]
220226
/*

benches/bigdecimal_vs_rust_decimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(not)]
12
#![feature(test)]
23
extern crate test;
34
// cargo +nightly bench --bench bigdecimal
@@ -6,7 +7,6 @@ use rust_decimal::Decimal;
67
use rust_decimal::RoundingStrategy::RoundHalfUp;
78
// 两个库的Zero, One Trait都是用的同一个crate
89
use bigdecimal::{BigDecimal, One, Signed, ToPrimitive, Zero};
9-
use num_bigint::BigInt;
1010
use serde::{Deserialize, Serialize};
1111
use std::str::FromStr;
1212

benches/deserialize_string_enum_u8_bool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(not)]
12
#![feature(test)]
23
extern crate test;
34
use serde::{Deserialize, Serialize};

examples/actix_response_channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl Handler<Messages> for MyActor {
5353
}
5454
}
5555

56-
#[actix_rt::main]
56+
#[actix_web::main]
5757
async fn main() {
5858
// Start MyActor in current thread
5959
let addr = MyActor.start();

examples/actix_ring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
1010
或者使用actix_rt的宏
1111
12-
#[actix_rt::main]
12+
#[actix_web::main]
1313
async fn main() {
1414
}
1515

examples/actix_web_http_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct Form {
77
user_id: u32,
88
}
99

10-
#[actix_rt::main]
10+
#[actix_web::main]
1111
async fn main() {
1212
http_post_echo_server().await;
1313
}

examples/actix_web_mut_global_data.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ use std::sync::{Arc, Mutex};
55
// FIXME Data中出现Arc会出现`Double Arc`问题,不推荐以下写法
66
#[actix_web::get("/")]
77
async fn count_data(counter: web::Data<Arc<Mutex<Data>>>) -> HttpResponse {
8-
log::info!("before lock");
8+
println!("before lock");
99
let mut data = counter.lock().unwrap();
10-
log::info!("after lock");
11-
log::info!("before add, data={}", data.0);
10+
println!("after lock");
11+
println!("before add, data={}", data.0);
1212
data.0 += 1;
13-
log::info!("after add, data={}", data.0);
13+
println!("after add, data={}", data.0);
1414
HttpResponse::Ok().body(format!("{}", data.0))
1515
}
1616

1717
// 摘抄自官方例子
1818
#[actix_web::get("/app_data")]
1919
async fn count_app_data(data: web::Data<AppData>) -> HttpResponse {
20-
log::info!("before lock");
20+
println!("before lock");
2121
let mut counter = data.0.lock().unwrap();
22-
log::info!("after lock");
23-
log::info!("before add, data={}", counter);
22+
println!("after lock");
23+
println!("before add, data={}", counter);
2424
*counter += 1;
25-
log::info!("before add, data={}", counter);
25+
println!("before add, data={}", counter);
2626
HttpResponse::Ok().body(format!("{}", counter))
2727
}
2828

@@ -31,9 +31,8 @@ struct Data(pub u32);
3131
struct AppData(Mutex<i32>);
3232

3333
// TODO 个人认为更好的解决方案是once_cell或actomic,如果是可变全局变量就用再套一层Mutex/RwLock
34-
#[actix_rt::main]
34+
#[actix_web::main]
3535
async fn main() -> std::io::Result<()> {
36-
log4rs::init_file("config.toml/log4rs.yml", Default::default()).unwrap();
3736
// FIXME actix2.0版本app_data在HttpServer::new的外面(main函数作用域)中初始化才能正常使用(否则发10个请求counter可能才加到2)
3837
let app_data = web::Data::new(AppData(Mutex::new(0)));
3938
// FIXME actix2.0版本data在HttpServer::new的外面(main函数作用域)中初始化才能正常使用(否则发10个请求counter可能才加到2)

examples/actix_web_path_segement_params.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use actix_web::{get, test, web, App, HttpRequest, HttpResponse};
44
fn path_segment_param(req: HttpRequest, path: web::Path<(u32,)>) -> HttpResponse {
55
// uri: /user/123, path: None, skip: 9, segments: [("id", Segment(6, 9))]
66
dbg!(req.clone());
7-
println!("path.0 = {}", path.0);
7+
println!("path.0 = {}", path.0.0);
88
println!("&req.match_info()[\"id\"] = {}", &req.match_info()["id"]);
99
println!(
1010
"req.match_info().query(\"id\") = {}",
@@ -23,7 +23,7 @@ async fn test_path_segment_param() {
2323
test::call_service(&mut app_service, req).await;
2424
}
2525

26-
#[actix_rt::main]
26+
#[actix_web::main]
2727
async fn main() {
2828
test_path_segment_param().await;
2929
}

examples/actix_web_query_string_params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async fn test_query_string_params() {
3232
println!("response = {:#?}", resp);
3333
}
3434

35-
#[actix_rt::main]
35+
#[actix_web::main]
3636
async fn main() {
3737
test_query_string_params().await;
3838
}

examples/actix_web_stream_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async fn response_body() -> HttpResponse {
99
HttpResponse::Ok().streaming(rx_body)
1010
}
1111

12-
#[actix_rt::main]
12+
#[actix_web::main]
1313
async fn main() -> std::io::Result<()> {
1414
actix_web::HttpServer::new(move || {
1515
actix_web::App::new()

examples/actix_web_unit_test_mock_post_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async fn test_post_form() {
2121
println!("response = {:#?}", resp);
2222
}
2323

24-
#[actix_rt::main]
24+
#[actix_web::main]
2525
async fn main() {
2626
test_post_form().await;
2727
}

examples/actix_web_unit_test_string_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub async fn get_index() -> impl Responder {
55
"Hello World"
66
}
77

8-
#[actix_rt::main]
8+
#[actix_web::main]
99
async fn main() {
1010
let mut app_service = test::init_service(App::new().service(get_index)).await;
1111
let req = test::TestRequest::default().to_request();

examples/chrono_datetime.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unused_imports)]
12
use chrono::{Date, Datelike, Local, NaiveTime, TimeZone, Timelike, Weekday};
23
use std::ops::Add;
34

examples/const_fn.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const fn gcd(x: u32, y: u32) -> u32 {
2+
let (mut a, mut b) = if x > y {(x, y)} else {(y, x)};
3+
let mut temp = a % b;
4+
while temp != 0 {
5+
a = b;
6+
b = temp;
7+
temp = a % b;
8+
}
9+
b
10+
}
11+
12+
const GCD: u32 = gcd(18, 12);
13+
14+
const fn fib(n: u32) -> u32 {
15+
const fn helper(n: u32, a: u32, b: u32) -> u32 {
16+
return if n <= 2 {
17+
b
18+
} else {
19+
helper(n - 1, b, a + b)
20+
}
21+
}
22+
helper(n, 1, 1)
23+
}
24+
25+
// 1 1 2 3 5
26+
const FIB_5: u32 = fib(5);
27+
28+
fn main() {
29+
dbg!(GCD);
30+
dbg!(FIB_5);
31+
}

examples/const_generic.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![feature(const_generics)]
2+
3+
use std::mem::MaybeUninit;
4+
5+
/**
6+
当前(1.49.0)常量泛型的不足
7+
1. T只能是整数、布尔值,也不允许使用引用(意味着不能用胖指针的字符串)
8+
*/
9+
struct Array<T, const N: usize> {
10+
items: [MaybeUninit<T>; N],
11+
length: usize
12+
}
13+
14+
/**
15+
为什么常量泛型的长度会有花括号:
16+
[https://internals.rust-lang.org/t/lang-team-minutes-const-generics/5090](https://internals.rust-lang.org/t/lang-team-minutes-const-generics/5090)
17+
> Syntactically we may distinguish these expressions with braces
18+
两个常量表达式的typechecking是T-lang团队的主要问题,目前{N+1}和{1+N}两个常量泛型长度会不一样
19+
*/
20+
impl<T, const N: usize> Array<T, {N}> {
21+
fn new() -> Self {
22+
// Self {
23+
// items: [MaybeUninit<T>; N],
24+
// length: N
25+
// }
26+
todo!("")
27+
}
28+
}
29+
30+
fn main() {
31+
// fn foo() -> impl ToString {
32+
// "Hello, world!"
33+
// }
34+
// let _: &str = foo();
35+
// let a: Array<bool, 1> = Array::new();
36+
}

examples/generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(generators, generator_trait)]
2-
use std::future::Future;
2+
// use std::future::Future;
33
use std::ops::Generator;
44
use std::pin::Pin;
55

examples/hyper_http_client.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#[cfg(test)]
12
use bytes::buf::BufExt;
23

34
#[cfg(debug_assertions)]
45
const URL: &str = "https://jsonplaceholder.typicode.com/users/1";
56

6-
#[tokio::test(core_threads = 1)]
7+
// #[tokio::test(core_threads = 1)]
8+
#[tokio::test]
79
async fn simple_http_request() -> Result<(), Box<dyn std::error::Error>> {
810
let res = hyper::Client::new()
911
.get(URL.replace("https", "http").parse()?)
@@ -14,7 +16,7 @@ async fn simple_http_request() -> Result<(), Box<dyn std::error::Error>> {
1416
Ok(())
1517
}
1618

17-
#[tokio::test(core_threads = 1)]
19+
#[tokio::test]
1820
async fn hyper_https_request() -> Result<(), Box<dyn std::error::Error>> {
1921
let https_client =
2022
hyper::Client::builder().build::<_, hyper::Body>(hyper_tls::HttpsConnector::new());

examples/inline_assembly_asm.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#![feature(asm)]
22

3-
// cargo +nightly run --example inline_assembly
43
fn main() {
54
unsafe {
6-
// asm!("NOP");
7-
llvm_asm!("NOP");
5+
asm!("NOP");
86
}
97
println!("after NOP");
108
}

0 commit comments

Comments
 (0)