Skip to content

Commit

Permalink
perf: #![forbid(clippy::unwrap_used)]
Browse files Browse the repository at this point in the history
  • Loading branch information
sargon64 committed Mar 2, 2024
1 parent ce4d3c9 commit 01f7632
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 172 deletions.
106 changes: 102 additions & 4 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ futures-util = "0.3.28"
# juniper_subscriptions = "0.16.0"
# juniper_warp = { version = "0.7.0", features = ["subscriptions"] }
lazy_static = "1.4.0"
log = "0.4.20"
# log = "0.4.20"
poem = "2.0.0"
prost = "0.11.9"
prost-types = "0.11.9"
Expand All @@ -40,6 +40,8 @@ tokio = { version = "1.31.0", features = ["full"] }
tokio-tungstenite = { version = "0.20.0", features = [
"rustls-tls-native-roots"
] }
tracing = { version = "0.1.40", features = ["log"] }
tracing-subscriber = { version = "0.3.18", features = ["chrono", "env-filter"] }
uuid = { version = "1.7", features = ["serde", "v4"] }
# warp = { version = "0.3.5", features = ["tokio-rustls"] }

Expand Down
13 changes: 10 additions & 3 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use futures_util::{stream::{SplitStream, SplitSink}, StreamExt, SinkExt, Stream}
use prost::Message as _;
use tokio::net::TcpStream;
use tokio_tungstenite::{WebSocketStream, MaybeTlsStream, tungstenite::Message};
use crate::{proto::{models, packet}};
use tracing::error;
use crate::proto::{models, packet};

#[derive(Debug)]
pub struct TAConnection {
Expand All @@ -18,7 +19,7 @@ impl TAConnection {
let (ws_stream, _) = match tokio_tungstenite::connect_async(uri).await {
Ok(c) => c,
Err(_) => {
log::error!("Failed to connect to server. Are you sure you're connecting to the overlay websocket?");
error!("Failed to connect to server. Are you sure you're connecting to the overlay websocket?");
return Err(anyhow::anyhow!("Failed to connect to server. Are you sure you're connecting to the overlay websocket?"));
},
};
Expand All @@ -42,7 +43,13 @@ impl TAConnection {
}))
};

ws_tx.send(Message::Binary(connect.encode_to_vec())).await.unwrap();
match ws_tx.send(Message::Binary(connect.encode_to_vec())).await {
Ok(_) => {},
Err(e) => {
error!("Failed to send connect packet. {:#?}", e);
return Err(anyhow::anyhow!("Failed to send connect packet. {:#?}", e));
},
};

Ok(TAConnection {
ws_rx,
Expand Down
4 changes: 2 additions & 2 deletions src/gql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ pub struct Query;

#[Object]
impl Query {
async fn state<'ctx>(&self, _ctx: &Context<'ctx>) -> GQLTAState {
async fn state<'ctx>(&self, _ctx: &Context<'ctx>) -> anyhow::Result<GQLTAState> {
TA_STATE.read().await.into_gql().await
}

async fn match_by_id<'ctx>(&self, _ctx: &Context<'ctx>, id: Uuid) -> Option<Match> {
async fn match_by_id<'ctx>(&self, _ctx: &Context<'ctx>, id: Uuid) -> anyhow::Result<Option<Match>> {
TA_STATE.read().await.get_single_match_gql(id).await
}

Expand Down
Loading

0 comments on commit 01f7632

Please sign in to comment.