Răsfoiți Sursa

Merge pull request #9628 from shyamsundarb-arch/master

Fixed actix build error. Upgraded rust to 2024 edition
Mike Smith 5 luni în urmă
părinte
comite
b3cd902ef3

Fișier diff suprimat deoarece este prea mare
+ 318 - 204
frameworks/Rust/actix/Cargo.lock


+ 24 - 25
frameworks/Rust/actix/Cargo.toml

@@ -1,7 +1,7 @@
 [package]
 name = "tfb-actix"
-version = "3.0.0"
-edition = "2018"
+version = "4.0.0"
+edition = "2024"
 
 [[bin]]
 name = "tfb-web"
@@ -28,41 +28,40 @@ name = "tfb-web-pg-deadpool"
 path = "src/main_pg_deadpool.rs"
 
 [dependencies]
-anyhow = "1"
-actix = "0.13"
-actix-web = "4.3.1"
-actix-http = "3.3.1"
-actix-rt = "2"
-actix-codec = "0.4"
+anyhow = "1.0.96"
+actix = "0.13.5"
+actix-web = "4.9.0"
+actix-http = "3.9.0"
+actix-rt = "2.10.0"
+actix-codec = "0.5"
 actix-server = "2"
 actix-service = "2"
 
-askama = "0.11"
+askama = "0.12"
 bytes = "1"
-diesel = { version = "1.4", features = ["postgres"] }
-env_logger = "0.9"
-futures = "0.3.7"
-http = "0.2"
+diesel = { version = "2.2.7", features = ["postgres"] }
+env_logger = "0.11"
+futures = "0.3.31"
 log = { version = "0.4", features = ["release_max_level_debug"] }
 num_cpus = "1.13"
-rand = { version = "0.8", features = ["small_rng"] }
+rand = { version = "0.9", features = ["small_rng"] }
 serde = { version = "1", features = ["derive"] }
 serde_json = "1"
-simd-json = "0.4"
-simd-json-derive = "0.12"
-snmalloc-rs = "0.2.6"
+simd-json = "0.14"
+simd-json-derive = "0.15"
+snmalloc-rs = "0.3.8"
 tokio = { version = "1", features = ["full"] }
-tokio-util = "0.7.8"
-tokio-postgres = "0.7.5"
-deadpool-postgres = "0.10.1"
-mongodb = "2.2.0"
-url = "2.1"
-v_htmlescape = "0.14"
+tokio-util = "0.7.13"
+tokio-postgres = "0.7.13"
+deadpool-postgres = "0.14.1"
+mongodb = "3.2.1"
+url = "2.5"
+v_htmlescape = "0.15"
 yarte = { version = "0.15", features = ["bytes-buf"] }
 
 [build-dependencies]
-askama = "0.11"
-bindgen = "0.59"
+askama = "0.12"
+bindgen = "0.71"
 
 [profile.release]
 lto = true

+ 1 - 1
frameworks/Rust/actix/actix-http.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.58
+FROM rust:1.85
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 

+ 1 - 1
frameworks/Rust/actix/actix-server.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.58
+FROM rust:1.85
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 

+ 1 - 1
frameworks/Rust/actix/actix-web-diesel.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.58
+FROM rust:1.85
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 

+ 1 - 1
frameworks/Rust/actix/actix-web-mongodb.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.57.0
+FROM rust:1.85
 
 ENV ACTIX_TECHEMPOWER_MONGODB_URL=mongodb://tfb-database:27017
 

+ 1 - 1
frameworks/Rust/actix/actix-web-pg-deadpool.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.57.0
+FROM rust:1.85
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 

+ 1 - 1
frameworks/Rust/actix/actix.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.58
+FROM rust:1.85.0
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 

+ 8 - 8
frameworks/Rust/actix/benchmark_config.json

@@ -6,7 +6,7 @@ use bytes::{Bytes, BytesMut};
 use futures::{
     stream::futures_unordered::FuturesUnordered, FutureExt, StreamExt, TryStreamExt,
 };
-use rand::{rngs::SmallRng, thread_rng, Rng, SeedableRng};
+use rand::{rngs::SmallRng, Rng, SeedableRng};
 use tokio_postgres::{connect, types::ToSql, Client, NoTls, Statement};
 
 use crate::{
@@ -101,9 +101,9 @@ impl PgConnection {
     }
 
     pub async fn get_world(&self) -> Result<Bytes, PgError> {
-        let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
+        let mut rng = SmallRng::from_rng(&mut rand::rng());
 
-        let random_id = (rng.gen::<u32>() % 10_000 + 1) as i32;
+        let random_id = (rng.random::<u32>() % 10_000 + 1) as i32;
 
         let world = self.query_one_world(random_id).await?;
         let mut body = BytesMut::with_capacity(40);
@@ -113,12 +113,12 @@ impl PgConnection {
     }
 
     pub async fn get_worlds(&self, num: usize) -> Result<Vec<World>, PgError> {
-        let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
+        let mut rng = SmallRng::from_rng(&mut rand::rng());
 
         let worlds = FuturesUnordered::new();
 
         for _ in 0..num {
-            let w_id = (rng.gen::<u32>() % 10_000 + 1) as i32;
+            let w_id = (rng.random::<u32>() % 10_000 + 1) as i32;
             worlds.push(self.query_one_world(w_id));
         }
 
@@ -126,13 +126,13 @@ impl PgConnection {
     }
 
     pub async fn update(&self, num: u16) -> Result<Vec<World>, PgError> {
-        let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
+        let mut rng = SmallRng::from_rng(&mut rand::rng());
 
         let worlds = FuturesUnordered::new();
 
         for _ in 0..num {
-            let id = (rng.gen::<u32>() % 10_000 + 1) as i32;
-            let w_id = (rng.gen::<u32>() % 10_000 + 1) as i32;
+            let id = (rng.random::<u32>() % 10_000 + 1) as i32;
+            let w_id = (rng.random::<u32>() % 10_000 + 1) as i32;
 
             worlds.push(self.query_one_world(w_id).map(move |res| match res {
                 Ok(mut world) => {

+ 15 - 14
frameworks/Rust/actix/src/db_diesel.rs

@@ -3,7 +3,7 @@
 use std::io;
 
 use actix::prelude::*;
-use diesel::{prelude::*, result::Error};
+use diesel::prelude::*;
 use rand::{rngs::SmallRng, Rng, SeedableRng};
 
 use crate::models;
@@ -18,7 +18,7 @@ impl DbExecutor {
         DbExecutor {
             conn: PgConnection::establish(db_url)
                 .unwrap_or_else(|_| panic!("Error connecting to {}", db_url)),
-            rng: SmallRng::from_entropy(),
+            rng: SmallRng::from_os_rng(),
         }
     }
 }
@@ -39,10 +39,10 @@ impl Handler<RandomWorld> for DbExecutor {
     fn handle(&mut self, _: RandomWorld, _: &mut Self::Context) -> Self::Result {
         use crate::schema::world::dsl::*;
 
-        let random_id = self.rng.gen_range(1..10_001);
+        let random_id = self.rng.random_range(1..10_001);
         match world
             .filter(id.eq(random_id))
-            .load::<models::World>(&self.conn)
+            .load::<models::World>(&mut self.conn)
         {
             Ok(mut items) => Ok(items.pop().unwrap()),
             Err(_) => Err(io::Error::new(io::ErrorKind::Other, "Database error")),
@@ -64,8 +64,8 @@ impl Handler<RandomWorlds> for DbExecutor {
 
         let mut worlds = Vec::with_capacity(msg.0 as usize);
         for _ in 0..msg.0 {
-            let w_id = self.rng.gen_range(1..10_001);
-            let w = match world.filter(id.eq(w_id)).load::<models::World>(&self.conn) {
+            let w_id = self.rng.random_range(1..10_001);
+            let w = match world.filter(id.eq(w_id)).load::<models::World>(&mut self.conn) {
                 Ok(mut items) => items.pop().unwrap(),
                 Err(_) => {
                     return Err(io::Error::new(io::ErrorKind::Other, "Database error"));
@@ -91,27 +91,28 @@ impl Handler<UpdateWorld> for DbExecutor {
 
         let mut worlds = Vec::with_capacity(msg.0 as usize);
         for _ in 0..msg.0 {
-            let w_id: i32 = self.rng.gen_range(1..10_001);
-            let mut w = match world.filter(id.eq(w_id)).load::<models::World>(&self.conn) {
+            let w_id: i32 = self.rng.random_range(1..10_001);
+            let mut w = match world.filter(id.eq(w_id)).load::<models::World>(&mut self.conn) {
                 Ok(mut items) => items.pop().unwrap(),
                 Err(_) => {
                     return Err(io::Error::new(io::ErrorKind::Other, "Database error"));
                 }
             };
-            w.randomnumber = self.rng.gen_range(1..10_001);
+            w.randomnumber = self.rng.random_range(1..10_001);
             worlds.push(w);
         }
         worlds.sort_by_key(|w| w.id);
 
-        let _ = self.conn.transaction::<(), Error, _>(|| {
+        self.conn.transaction(|conn| {
             for w in &worlds {
-                let _ = diesel::update(world)
+                diesel::update(world)
                     .filter(id.eq(w.id))
                     .set(randomnumber.eq(w.randomnumber))
-                    .execute(&self.conn);
+                    .execute(conn)?;
             }
             Ok(())
-        });
+        })
+        .map_err(|e: diesel::result::Error| io::Error::new(io::ErrorKind::Other, e))?;
 
         Ok(worlds)
     }
@@ -129,7 +130,7 @@ impl Handler<TellFortune> for DbExecutor {
     fn handle(&mut self, _: TellFortune, _: &mut Self::Context) -> Self::Result {
         use crate::schema::fortune::dsl::*;
 
-        match fortune.load::<models::Fortune>(&self.conn) {
+        match fortune.load::<models::Fortune>(&mut self.conn) {
             Ok(mut items) => {
                 items.push(models::Fortune {
                     id: 0,

+ 2 - 1
frameworks/Rust/actix/src/main_http.rs

@@ -23,6 +23,7 @@ use crate::{
     utils::Writer,
 };
 
+#[allow(dead_code)]
 #[derive(Debug)]
 enum Error {
     Pg(PgError),
@@ -134,7 +135,7 @@ impl Service<Request> for App {
             }
 
             _ => Box::pin(ok(Response::with_body(
-                http::StatusCode::NOT_FOUND,
+                StatusCode::NOT_FOUND,
                 Bytes::new(),
             ))),
         }

+ 6 - 7
frameworks/Rust/actix/src/main_mongodb.rs

@@ -28,12 +28,12 @@ async fn find_random_world(data: web::Data<Data>) -> Result<World> {
     let runtime = data.tokio_runtime.clone();
     runtime
         .spawn(async move {
-            let mut rng = SmallRng::from_entropy();
-            let id = (rng.gen::<u32>() % 10_000 + 1) as i32;
+            let mut rng = SmallRng::from_os_rng();
+            let id = (rng.random::<u32>() % 10_000 + 1) as i32;
 
             let coll = data.client.database("hello_world").collection("world");
             let world = coll
-                .find_one(doc! { "id": id as f32 }, None)
+                .find_one(doc! { "id": id as f32 })
                 .await?
                 .expect("should find world");
             Ok(world)
@@ -101,10 +101,10 @@ async fn updates(
 
     let mut worlds = find_random_worlds(data, query.q).await?;
 
-    let mut rng = SmallRng::from_entropy();
+    let mut rng = SmallRng::from_os_rng();
     let mut updates = Vec::new();
     for world in worlds.iter_mut() {
-        let new_random_number = (rng.gen::<u32>() % 10_000 + 1) as i32;
+        let new_random_number = (rng.random::<u32>() % 10_000 + 1) as i32;
         updates.push(doc! {
             "q": { "id": world.id }, "u": { "$set": { "randomNumber": new_random_number }}
         });
@@ -121,7 +121,6 @@ async fn updates(
                         "updates": updates,
                         "ordered": false,
                     },
-                    None,
                 )
                 .await
         })
@@ -145,7 +144,7 @@ async fn fortune(data: web::Data<Data>) -> Result<HttpResponse<Vec<u8>>> {
         let fortunes_cursor = client
             .database("hello_world")
             .collection::<Fortune>("fortune")
-            .find(None, None)
+            .find(doc! {})
             .await?;
 
         let mut fortunes: Vec<Fortune> = fortunes_cursor.try_collect().await?;

+ 4 - 4
frameworks/Rust/actix/src/main_pg_deadpool.rs

@@ -27,8 +27,8 @@ async fn find_random_world(pool: &Pool) -> Result<World> {
         .await
         .unwrap();
 
-    let mut rng = SmallRng::from_entropy();
-    let id = (rng.gen::<u32>() % 10_000 + 1) as i32;
+    let mut rng = SmallRng::from_os_rng();
+    let id = (rng.random::<u32>() % 10_000 + 1) as i32;
 
     let row = conn.query_one(&world, &[&id]).await?;
 
@@ -95,14 +95,14 @@ async fn updates(
 ) -> Result<HttpResponse<Vec<u8>>> {
     let mut worlds = find_random_worlds(&data, query.q).await?;
 
-    let mut rng = SmallRng::from_entropy();
+    let mut rng = SmallRng::from_os_rng();
 
     let mut updates = "UPDATE world SET randomnumber = CASE id ".to_string();
     let mut params: Vec<&(dyn ToSql + Sync)> = Vec::with_capacity(query.q as usize * 3);
 
     let mut n_params = 1;
     for world in worlds.iter_mut() {
-        let new_random_number = (rng.gen::<u32>() % 10_000 + 1) as i32;
+        let new_random_number = (rng.random::<u32>() % 10_000 + 1) as i32;
         write!(&mut updates, "when ${} then ${} ", n_params, n_params + 1).unwrap();
         world.randomnumber = new_random_number;
         n_params += 2;

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff