From 229211689a3e31d0503354b1e3d5420acd367815 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Thu, 5 Oct 2023 21:19:28 +0200 Subject: [PATCH] try conn --- src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b2e0b38..6059431 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,10 +18,14 @@ pub struct QuadWs { channel: WsChannnel, } impl QuadWs { - pub fn new(url: String) -> Self { - Self { - channel: ws_open_rust(url).unwrap() + pub fn new(url: String) -> Option { + let conn = ws_open_rust(url); + if conn.is_none() { + return None; } + Some(Self { + channel: conn.unwrap(), + }) } pub fn write(&mut self, data: Vec) -> bool { ws_write_rust(&mut self.channel, data) @@ -33,12 +37,12 @@ impl QuadWs { ws_read_rust(&mut self.channel) } pub fn connected(&mut self) -> bool { - if let QuadWsState::WsConnected = self.state(){ + if let QuadWsState::WsConnected = self.state() { return true; } false } - pub fn revive(&mut self){ + pub fn revive(&mut self) { ws_revive_rust(&mut self.channel); } pub fn state(&mut self) -> QuadWsState {