From 603e8d98704a408ebf134f5df83884fb0ce6a8fb Mon Sep 17 00:00:00 2001 From: Ivan Folgueira Bande Date: Mon, 18 Nov 2024 10:23:56 +0100 Subject: [PATCH] some code cleanup --- examples/Cargo.lock | 1 + examples/tic-tac-toe-gui/src/main.rs | 23 +++++------------------ waku-bindings/src/node/events.rs | 2 +- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/examples/Cargo.lock b/examples/Cargo.lock index 101e5d6..f3426b5 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -4344,6 +4344,7 @@ dependencies = [ "ctrlc", "eframe", "egui", + "secp256k1 0.26.0", "serde", "serde_json", "tokio", diff --git a/examples/tic-tac-toe-gui/src/main.rs b/examples/tic-tac-toe-gui/src/main.rs index 73ffebf..abc5728 100644 --- a/examples/tic-tac-toe-gui/src/main.rs +++ b/examples/tic-tac-toe-gui/src/main.rs @@ -1,18 +1,13 @@ use eframe::egui; -use secp256k1::SecretKey; use serde::{Deserialize, Serialize}; -use std::cell::OnceCell; use std::str::from_utf8; -use std::sync::Arc; -use std::sync::Mutex; -use std::str::FromStr; -use std::time::SystemTime; -use std::time::{Duration, Instant}; +use std::sync::{Arc, Mutex}; +use std::time::{SystemTime, Duration}; use tokio::sync::mpsc; use waku::{ - waku_new, Encoding, Event, Initialized, LibwakuResponse, Multiaddr, Running, WakuContentTopic, - WakuMessage, WakuNodeConfig, WakuNodeContext, WakuNodeHandle, + waku_new, Encoding, Event, LibwakuResponse, WakuContentTopic, + WakuMessage, WakuNodeConfig, WakuNodeHandle, }; #[derive(Serialize, Deserialize, PartialEq, Debug, Copy, Clone)] @@ -28,13 +23,6 @@ struct GameState { moves_left: usize, } -#[derive(Clone)] -struct MoveMessage { - row: usize, - col: usize, - player: Player, -} - struct TicTacToeApp { game_state: Arc>, waku: WakuNodeHandle, @@ -95,7 +83,7 @@ impl TicTacToeApp { }; // Establish a closure that handles the incoming messages - self.waku.ctx.waku_set_event_callback(my_closure); + self.waku.ctx.waku_set_event_callback(my_closure).expect("set event call back working"); // Subscribe to desired topic self.waku.relay_subscribe(&self.game_topic.to_string()).expect("waku should subscribe"); @@ -235,7 +223,6 @@ impl eframe::App for TicTacToeApp { ui.label(format!("You are playing as: {:?}", player_role)); // Draw the game board and handle the game state - let text_size = 32.0; let board_size = ui.available_size(); let cell_size = board_size.x / 4.0; diff --git a/waku-bindings/src/node/events.rs b/waku-bindings/src/node/events.rs index 1a236aa..673d4f5 100644 --- a/waku-bindings/src/node/events.rs +++ b/waku-bindings/src/node/events.rs @@ -59,7 +59,7 @@ impl WakuNodeContext { /// which are used to react to asynchronous events in Waku pub fn waku_set_event_callback( &self, - mut closure: F, + closure: F, ) -> Result<(), String> { if let Ok(mut boxed_closure) = self.msg_observer.lock() { *boxed_closure = Box::new(closure);