Skip to content

Commit c347a8c

Browse files
committed
feat: remove dyn
1 parent 8bf1c06 commit c347a8c

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

frameworks/Rust/hyperlane/src/db.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub async fn init_db() {
158158
}
159159

160160
#[inline]
161-
pub async fn random_world_row(db_pool: &DbPoolConnection) -> Result<QueryRow, Box<dyn Error>> {
161+
pub async fn random_world_row(db_pool: &DbPoolConnection) -> QueryRow {
162162
let random_id: i32 = rand::rng().random_range(1..=RANDOM_MAX);
163163
let sql: String = format!(
164164
"SELECT id, randomNumber FROM {} WHERE id = {}",
@@ -167,19 +167,19 @@ pub async fn random_world_row(db_pool: &DbPoolConnection) -> Result<QueryRow, Bo
167167
if let Ok(rows) = sqlx::query(&sql).fetch_one(db_pool).await {
168168
let id: i32 = rows.get(KEY_ID);
169169
let random_number: i32 = rows.get(KEY_RANDOM_NUMBER);
170-
return Ok(QueryRow::new(id, random_number));
170+
return QueryRow::new(id, random_number);
171171
}
172-
return Ok(QueryRow::new(1, 1));
172+
QueryRow::new(1, 1)
173173
}
174174

175175
#[inline]
176-
pub async fn update_world_rows(limit: Queries) -> Result<Vec<QueryRow>, Box<dyn Error>> {
176+
pub async fn update_world_rows(limit: Queries) -> Vec<QueryRow> {
177177
let db_pool: DbPoolConnection = get_db_connection().await;
178178
let (sql, data) = get_update_data(limit).await;
179179
spawn(async move {
180180
let _ = sqlx::query(&sql).execute(&db_pool).await;
181181
});
182-
Ok(data)
182+
data
183183
}
184184

185185
#[inline]
@@ -197,7 +197,7 @@ pub async fn all_world_row() -> Vec<PgRow> {
197197
pub async fn get_some_row_id(limit: Queries, db_pool: &DbPoolConnection) -> Vec<QueryRow> {
198198
let mut res: Vec<QueryRow> = Vec::with_capacity(limit as usize);
199199
for _ in 0..limit {
200-
let tem: QueryRow = random_world_row(db_pool).await.unwrap_or_default();
200+
let tem: QueryRow = random_world_row(db_pool).await;
201201
res.push(tem);
202202
}
203203
res

frameworks/Rust/hyperlane/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) use sqlx::{
3131
postgres::{PgPoolOptions, PgRow},
3232
Pool, Postgres, Row,
3333
};
34-
pub(crate) use std::{error::Error, fmt, sync::Arc};
34+
pub(crate) use std::{fmt, sync::Arc};
3535
pub(crate) use utils::*;
3636

3737
#[tokio::main]

frameworks/Rust/hyperlane/src/route.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub async fn plaintext(controller_data: ControllerData) {
2222
#[inline]
2323
pub async fn db(controller_data: ControllerData) {
2424
let db_connection: DbPoolConnection = get_db_connection().await;
25-
let query_row: QueryRow = random_world_row(&db_connection).await.unwrap();
25+
let query_row: QueryRow = random_world_row(&db_connection).await;
2626
let _ = controller_data
2727
.set_response_body(serde_json::to_string(&query_row).unwrap_or_default())
2828
.await;
@@ -40,9 +40,8 @@ pub async fn queries(controller_data: ControllerData) {
4040
let mut data: Vec<QueryRow> = Vec::with_capacity(queries as usize);
4141
let db_pool: DbPoolConnection = get_db_connection().await;
4242
for _ in 0..queries {
43-
let _ = random_world_row(&db_pool).await.map(|row| {
44-
data.push(row);
45-
});
43+
let row: QueryRow = random_world_row(&db_pool).await;
44+
data.push(row);
4645
}
4746
let _ = controller_data
4847
.set_response_body(serde_json::to_string(&data).unwrap_or_default())
@@ -82,7 +81,7 @@ pub async fn updates(controller_data: ControllerData) {
8281
.unwrap_or_default()
8382
.min(ROW_LIMIT as Queries)
8483
.max(1);
85-
let res: Vec<QueryRow> = update_world_rows(queries).await.unwrap();
84+
let res: Vec<QueryRow> = update_world_rows(queries).await;
8685
let _ = controller_data
8786
.set_response_body(serde_json::to_string(&res).unwrap_or_default())
8887
.await;

0 commit comments

Comments
 (0)