From 20451af880da8f37d6a5f1deaff0c8f8f8e3bb3a Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Mon, 18 Sep 2023 19:49:57 -0400 Subject: [PATCH] more clippy --- veilid-core/src/intf/wasm/protected_store.rs | 7 +-- .../src/network_manager/connection_manager.rs | 22 +------- veilid-core/src/network_manager/mod.rs | 2 +- veilid-core/src/network_manager/native/mod.rs | 14 +++--- .../src/network_manager/native/protocol/ws.rs | 4 +- .../network_manager/types/dial_info/mod.rs | 4 +- veilid-core/src/network_manager/wasm/mod.rs | 46 ++++++++--------- .../src/network_manager/wasm/protocol/mod.rs | 2 +- .../src/network_manager/wasm/protocol/ws.rs | 4 +- .../src/routing_table/routing_domains.rs | 8 +-- .../operations/operation_watch_value.rs | 15 ++++-- .../src/tests/common/test_protected_store.rs | 2 +- veilid-tools/src/timestamp.rs | 50 +++++++++++-------- veilid-tools/src/wasm.rs | 4 +- veilid-wasm/src/lib.rs | 30 +++++------ veilid-wasm/src/veilid_client_js.rs | 5 +- veilid-wasm/src/veilid_crypto_js.rs | 4 +- veilid-wasm/src/veilid_table_db_js.rs | 14 +++++- 18 files changed, 115 insertions(+), 122 deletions(-) diff --git a/veilid-core/src/intf/wasm/protected_store.rs b/veilid-core/src/intf/wasm/protected_store.rs index 087596ef..84216ad0 100644 --- a/veilid-core/src/intf/wasm/protected_store.rs +++ b/veilid-core/src/intf/wasm/protected_store.rs @@ -69,14 +69,11 @@ impl ProtectedStore { let vkey = self.browser_key_name(key.as_ref()); - let prev = match ls + let prev = ls .get_item(&vkey) .map_err(map_jsvalue_error) .wrap_err("exception_thrown")? - { - Some(_) => true, - None => false, - }; + .is_some(); ls.set_item(&vkey, value.as_ref()) .map_err(map_jsvalue_error) diff --git a/veilid-core/src/network_manager/connection_manager.rs b/veilid-core/src/network_manager/connection_manager.rs index d5ad429c..df2fe3ef 100644 --- a/veilid-core/src/network_manager/connection_manager.rs +++ b/veilid-core/src/network_manager/connection_manager.rs @@ -249,7 +249,7 @@ impl ConnectionManager { &self, dial_info: DialInfo, ) -> EyreResult> { - let peer_address = dial_info.to_peer_address(); + let peer_address = dial_info.peer_address(); let remote_addr = peer_address.socket_addr(); let mut preferred_local_address = self .network_manager() @@ -301,26 +301,6 @@ impl ConnectionManager { .await; match result_net_res { Ok(net_res) => { - // // If the connection 'already exists', then try one last time to return a connection from the table, in case - // // an 'accept' happened at literally the same time as our connect. A preferred local address must have been - // // specified otherwise we would have picked a different ephemeral port and this could not have happened - // if net_res.is_already_exists() && preferred_local_address.is_some() { - // // Make 'already existing' connection descriptor - // let conn_desc = ConnectionDescriptor::new( - // dial_info.to_peer_address(), - // SocketAddress::from_socket_addr(preferred_local_address.unwrap()), - // ); - // // Return the connection for this if we have it - // if let Some(conn) = self - // .arc - // .connection_table - // .get_connection_by_descriptor(conn_desc) - // { - // // Should not really happen, lets make sure we see this if it does - // log_net!(warn "== Returning existing connection in race: {:?}", conn_desc); - // return Ok(NetworkResult::Value(conn)); - // } - // } if net_res.is_value() || retry_count == 0 { // Successful new connection, return it break net_res; diff --git a/veilid-core/src/network_manager/mod.rs b/veilid-core/src/network_manager/mod.rs index d5708f9f..473d4d77 100644 --- a/veilid-core/src/network_manager/mod.rs +++ b/veilid-core/src/network_manager/mod.rs @@ -46,7 +46,7 @@ use storage_manager::*; #[cfg(target_arch = "wasm32")] use wasm::*; #[cfg(target_arch = "wasm32")] -pub use wasm::{LOCAL_NETWORK_CAPABILITIES, MAX_CAPABILITIES, PUBLIC_INTERNET_CAPABILITIES}; +pub use wasm::{/* LOCAL_NETWORK_CAPABILITIES, */ MAX_CAPABILITIES, PUBLIC_INTERNET_CAPABILITIES,}; //////////////////////////////////////////////////////////////////////////////////////// diff --git a/veilid-core/src/network_manager/native/mod.rs b/veilid-core/src/network_manager/native/mod.rs index 389eebbd..0cd77f0b 100644 --- a/veilid-core/src/network_manager/native/mod.rs +++ b/veilid-core/src/network_manager/native/mod.rs @@ -462,7 +462,7 @@ impl Network { } // Network accounting self.network_manager() - .stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64)); + .stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64)); Ok(NetworkResult::Value(())) }) @@ -507,7 +507,7 @@ impl Network { .await .wrap_err("send message failure")?); self.network_manager() - .stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64)); + .stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64)); // receive single response let mut out = vec![0u8; MAX_MESSAGE_SIZE]; @@ -552,7 +552,7 @@ impl Network { network_result_try!(pnc.send(data).await.wrap_err("send failure")?); self.network_manager() - .stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64)); + .stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64)); let out = network_result_try!(network_result_try!(timeout(timeout_ms, pnc.recv()) @@ -560,10 +560,8 @@ impl Network { .into_network_result()) .wrap_err("recv failure")?); - self.network_manager().stats_packet_rcvd( - dial_info.to_ip_addr(), - ByteCount::new(out.len() as u64), - ); + self.network_manager() + .stats_packet_rcvd(dial_info.ip_addr(), ByteCount::new(out.len() as u64)); Ok(NetworkResult::Value(out)) } @@ -676,7 +674,7 @@ impl Network { // Network accounting self.network_manager() - .stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64)); + .stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64)); Ok(NetworkResult::value(connection_descriptor)) }) diff --git a/veilid-core/src/network_manager/native/protocol/ws.rs b/veilid-core/src/network_manager/native/protocol/ws.rs index 4a3d09c6..a98519d6 100644 --- a/veilid-core/src/network_manager/native/protocol/ws.rs +++ b/veilid-core/src/network_manager/native/protocol/ws.rs @@ -20,7 +20,7 @@ const MAX_WS_BEFORE_BODY: usize = 2048; cfg_if! { if #[cfg(feature="rt-async-std")] { pub type WebsocketNetworkConnectionWSS = - DialInfo::WS { field1: _ }ketNetworkConnection>; + WebsocketNetworkConnection>; pub type WebsocketNetworkConnectionWS = WebsocketNetworkConnection; } else if #[cfg(feature="rt-tokio")] { pub type WebsocketNetworkConnectionWSS = @@ -306,7 +306,7 @@ impl WebsocketProtocolHandler { // Make our connection descriptor let descriptor = ConnectionDescriptor::new( - dial_info.to_peer_address(), + dial_info.peer_address(), SocketAddress::from_socket_addr(actual_local_addr), ); diff --git a/veilid-core/src/network_manager/types/dial_info/mod.rs b/veilid-core/src/network_manager/types/dial_info/mod.rs index c90dcc97..1940b80e 100644 --- a/veilid-core/src/network_manager/types/dial_info/mod.rs +++ b/veilid-core/src/network_manager/types/dial_info/mod.rs @@ -242,7 +242,7 @@ impl DialInfo { Self::WSS(di) => di.socket_address, } } - pub fn to_ip_addr(&self) -> IpAddr { + pub fn ip_addr(&self) -> IpAddr { match self { Self::UDP(di) => di.socket_address.ip_addr(), Self::TCP(di) => di.socket_address.ip_addr(), @@ -274,7 +274,7 @@ impl DialInfo { Self::WSS(di) => di.socket_address.socket_addr(), } } - pub fn to_peer_address(&self) -> PeerAddress { + pub fn peer_address(&self) -> PeerAddress { match self { Self::UDP(di) => PeerAddress::new(di.socket_address, ProtocolType::UDP), Self::TCP(di) => PeerAddress::new(di.socket_address, ProtocolType::TCP), diff --git a/veilid-core/src/network_manager/wasm/mod.rs b/veilid-core/src/network_manager/wasm/mod.rs index b9e66e8c..5924c5eb 100644 --- a/veilid-core/src/network_manager/wasm/mod.rs +++ b/veilid-core/src/network_manager/wasm/mod.rs @@ -32,18 +32,18 @@ pub const PUBLIC_INTERNET_CAPABILITIES: [Capability; PUBLIC_INTERNET_CAPABILITIE CAP_BLOCKSTORE, ]; -#[cfg(feature = "unstable-blockstore")] -const LOCAL_NETWORK_CAPABILITIES_LEN: usize = 3; -#[cfg(not(feature = "unstable-blockstore"))] -const LOCAL_NETWORK_CAPABILITIES_LEN: usize = 2; +// #[cfg(feature = "unstable-blockstore")] +// const LOCAL_NETWORK_CAPABILITIES_LEN: usize = 3; +// #[cfg(not(feature = "unstable-blockstore"))] +// const LOCAL_NETWORK_CAPABILITIES_LEN: usize = 2; -pub const LOCAL_NETWORK_CAPABILITIES: [Capability; LOCAL_NETWORK_CAPABILITIES_LEN] = [ - //CAP_RELAY, - CAP_DHT, - CAP_APPMESSAGE, - #[cfg(feature = "unstable-blockstore")] - CAP_BLOCKSTORE, -]; +// pub const LOCAL_NETWORK_CAPABILITIES: [Capability; LOCAL_NETWORK_CAPABILITIES_LEN] = [ +// //CAP_RELAY, +// CAP_DHT, +// CAP_APPMESSAGE, +// #[cfg(feature = "unstable-blockstore")] +// CAP_BLOCKSTORE, +// ]; pub const MAX_CAPABILITIES: usize = 64; @@ -149,7 +149,7 @@ impl Network { if self .network_manager() .address_filter() - .is_ip_addr_punished(dial_info.address().to_ip_addr()) + .is_ip_addr_punished(dial_info.address().ip_addr()) { return Ok(NetworkResult::no_connection_other("punished")); } @@ -173,7 +173,7 @@ impl Network { // Network accounting self.network_manager() - .stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64)); + .stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64)); Ok(NetworkResult::Value(())) }) @@ -202,7 +202,7 @@ impl Network { if self .network_manager() .address_filter() - .is_ip_addr_punished(dial_info.address().to_ip_addr()) + .is_ip_addr_punished(dial_info.address().ip_addr()) { return Ok(NetworkResult::no_connection_other("punished")); } @@ -227,7 +227,7 @@ impl Network { network_result_try!(pnc.send(data).await.wrap_err("send failure")?); self.network_manager() - .stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64)); + .stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64)); let out = network_result_try!(network_result_try!(timeout(timeout_ms, pnc.recv()) @@ -235,10 +235,8 @@ impl Network { .into_network_result()) .wrap_err("recv failure")?); - self.network_manager().stats_packet_rcvd( - dial_info.to_ip_addr(), - ByteCount::new(out.len() as u64), - ); + self.network_manager() + .stats_packet_rcvd(dial_info.ip_addr(), ByteCount::new(out.len() as u64)); Ok(NetworkResult::Value(out)) } @@ -273,7 +271,7 @@ impl Network { ConnectionHandleSendResult::Sent => { // Network accounting self.network_manager().stats_packet_sent( - descriptor.remote().to_socket_addr().ip(), + descriptor.remote().socket_addr().ip(), ByteCount::new(data_len as u64), ); @@ -324,7 +322,7 @@ impl Network { // Network accounting self.network_manager() - .stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64)); + .stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64)); Ok(NetworkResult::value(connection_descriptor)) }) @@ -434,11 +432,11 @@ impl Network { Vec::new() } - pub fn get_local_port(&self, protocol_type: ProtocolType) -> Option { + pub fn get_local_port(&self, _protocol_type: ProtocolType) -> Option { None } - pub fn get_preferred_local_address(&self, dial_info: &DialInfo) -> Option { + pub fn get_preferred_local_address(&self, _dial_info: &DialInfo) -> Option { None } @@ -456,7 +454,7 @@ impl Network { } pub fn get_protocol_config(&self) -> ProtocolConfig { - self.inner.lock().protocol_config.clone() + self.inner.lock().protocol_config } ////////////////////////////////////////// diff --git a/veilid-core/src/network_manager/wasm/protocol/mod.rs b/veilid-core/src/network_manager/wasm/protocol/mod.rs index 846cff18..c3f3392b 100644 --- a/veilid-core/src/network_manager/wasm/protocol/mod.rs +++ b/veilid-core/src/network_manager/wasm/protocol/mod.rs @@ -19,7 +19,7 @@ impl ProtocolNetworkConnection { timeout_ms: u32, address_filter: AddressFilter, ) -> io::Result> { - if address_filter.is_ip_addr_punished(dial_info.address().to_ip_addr()) { + if address_filter.is_ip_addr_punished(dial_info.address().ip_addr()) { return Ok(NetworkResult::no_connection_other("punished")); } match dial_info.protocol_type() { diff --git a/veilid-core/src/network_manager/wasm/protocol/ws.rs b/veilid-core/src/network_manager/wasm/protocol/ws.rs index 127122b3..670c70c9 100644 --- a/veilid-core/src/network_manager/wasm/protocol/ws.rs +++ b/veilid-core/src/network_manager/wasm/protocol/ws.rs @@ -56,7 +56,7 @@ impl WebsocketNetworkConnection { } pub fn descriptor(&self) -> ConnectionDescriptor { - self.descriptor.clone() + self.descriptor } // #[instrument(level = "trace", err, skip(self))] @@ -144,7 +144,7 @@ impl WebsocketProtocolHandler { // Make our connection descriptor let wnc = WebsocketNetworkConnection::new( - ConnectionDescriptor::new_no_local(dial_info.to_peer_address()), + ConnectionDescriptor::new_no_local(dial_info.peer_address()), wsmeta, wsio, ); diff --git a/veilid-core/src/routing_table/routing_domains.rs b/veilid-core/src/routing_table/routing_domains.rs index 5d280975..32eb0eec 100644 --- a/veilid-core/src/routing_table/routing_domains.rs +++ b/veilid-core/src/routing_table/routing_domains.rs @@ -399,8 +399,8 @@ impl RoutingDomainDetail for PublicInternetRoutingDomainDetail { dif_sort.clone() ) { // Ensure we aren't on the same public IP address (no hairpin nat) - if reverse_did.dial_info.to_ip_addr() - != target_did.dial_info.to_ip_addr() + if reverse_did.dial_info.ip_addr() + != target_did.dial_info.ip_addr() { // Can we receive a direct reverse connection? if !reverse_did.class.requires_signal() { @@ -433,8 +433,8 @@ impl RoutingDomainDetail for PublicInternetRoutingDomainDetail { dif_sort.clone(), ) { // Ensure we aren't on the same public IP address (no hairpin nat) - if reverse_udp_did.dial_info.to_ip_addr() - != target_udp_did.dial_info.to_ip_addr() + if reverse_udp_did.dial_info.ip_addr() + != target_udp_did.dial_info.ip_addr() { // The target and ourselves have a udp dialinfo that they can reach return ContactMethod::SignalHolePunch( diff --git a/veilid-core/src/rpc_processor/coders/operations/operation_watch_value.rs b/veilid-core/src/rpc_processor/coders/operations/operation_watch_value.rs index d2aefa79..77eea5a5 100644 --- a/veilid-core/src/rpc_processor/coders/operations/operation_watch_value.rs +++ b/veilid-core/src/rpc_processor/coders/operations/operation_watch_value.rs @@ -22,7 +22,12 @@ impl RPCOperationWatchValueQ { watcher: PublicKey, signature: Signature, ) -> Result { - if subkeys.len() > MAX_WATCH_VALUE_Q_SUBKEYS_LEN { + #[cfg(target_arch = "wasm32")] + let subkeys_len = subkeys.len() as usize; + #[cfg(not(target_arch = "wasm32"))] + let subkeys_len = subkeys.len(); + + if subkeys_len > MAX_WATCH_VALUE_Q_SUBKEYS_LEN { return Err(RPCError::protocol("WatchValueQ subkeys length too long")); } Ok(Self { @@ -37,8 +42,12 @@ impl RPCOperationWatchValueQ { // signature covers: key, subkeys, expiration, count, using watcher key fn make_signature_data(&self) -> Vec { - let mut sig_data = - Vec::with_capacity(PUBLIC_KEY_LENGTH + 4 + (self.subkeys.len() * 8) + 8 + 4); + #[cfg(target_arch = "wasm32")] + let subkeys_len = self.subkeys.len() as usize; + #[cfg(not(target_arch = "wasm32"))] + let subkeys_len = self.subkeys.len(); + + let mut sig_data = Vec::with_capacity(PUBLIC_KEY_LENGTH + 4 + (subkeys_len * 8) + 8 + 4); sig_data.extend_from_slice(&self.key.kind.0); sig_data.extend_from_slice(&self.key.value.bytes); for sk in self.subkeys.ranges() { diff --git a/veilid-core/src/tests/common/test_protected_store.rs b/veilid-core/src/tests/common/test_protected_store.rs index 2b242c0f..ac6bf5ec 100644 --- a/veilid-core/src/tests/common/test_protected_store.rs +++ b/veilid-core/src/tests/common/test_protected_store.rs @@ -70,7 +70,7 @@ pub async fn test_protected_store(ps: ProtectedStore) { assert_eq!(ps.load_user_secret("_test_broken").await.unwrap(), None); assert_eq!(ps.load_user_secret("_test_broken").await.unwrap(), None); assert!(ps.remove_user_secret("_test_key").await.unwrap()); - assert!(ps.remove_user_secret("_test_key").await.unwrap()); + assert!(!ps.remove_user_secret("_test_key").await.unwrap()); assert!(!ps.remove_user_secret("_test_key").await.unwrap()); assert!(!ps.remove_user_secret("_test_broken").await.unwrap()); diff --git a/veilid-tools/src/timestamp.rs b/veilid-tools/src/timestamp.rs index fb290966..2d995180 100644 --- a/veilid-tools/src/timestamp.rs +++ b/veilid-tools/src/timestamp.rs @@ -6,7 +6,7 @@ cfg_if! { pub fn get_timestamp() -> u64 { if is_browser() { - return (Date::now() * 1000.0f64) as u64; + (Date::now() * 1000.0f64) as u64 } else { panic!("WASM requires browser environment"); } @@ -23,28 +23,34 @@ cfg_if! { let show_month = show_year || now.get_utc_month() != date.get_utc_month(); let show_date = show_month || now.get_utc_date() != date.get_utc_date(); + let s_year = if show_year { + format!("{:04}/",date.get_utc_full_year()) + } else { + "".to_owned() + }; + let s_month = if show_month { + format!("{:02}/",date.get_utc_month()) + } else { + "".to_owned() + }; + let s_date = if show_date { + format!("{:02}-",date.get_utc_date()) + } else { + "".to_owned() + }; + let s_time = format!("{:02}:{:02}:{:02}.{:04}", + date.get_utc_hours(), + date.get_utc_minutes(), + date.get_utc_seconds(), + date.get_utc_milliseconds() + ); + format!("{}{}{}{}", - if show_year { - format!("{:04}/",date.get_utc_full_year()) - } else { - "".to_owned() - }, - if show_month { - format!("{:02}/",date.get_utc_month()) - } else { - "".to_owned() - }, - if show_date { - format!("{:02}-",date.get_utc_date()) - } else { - "".to_owned() - }, - format!("{:02}:{:02}:{:02}.{:04}", - date.get_utc_hours(), - date.get_utc_minutes(), - date.get_utc_seconds(), - date.get_utc_milliseconds() - )) + s_year, + s_month, + s_date, + s_time + ) } else { panic!("WASM requires browser environment"); } diff --git a/veilid-tools/src/wasm.rs b/veilid-tools/src/wasm.rs index 1a54aee5..187112ca 100644 --- a/veilid-tools/src/wasm.rs +++ b/veilid-tools/src/wasm.rs @@ -21,7 +21,7 @@ pub fn is_browser() -> bool { return cache != 0; } - let res = Reflect::has(&global().as_ref(), &"navigator".into()).unwrap_or_default(); + let res = Reflect::has(global().as_ref(), &"navigator".into()).unwrap_or_default(); CACHE.store(res as i8, Ordering::Relaxed); @@ -45,7 +45,7 @@ pub fn is_browser_https() -> bool { } pub fn get_wasm_global_string_value>(key: K) -> Option { - let Ok(v) = Reflect::get(&global().as_ref(), &JsValue::from_str(key.as_ref())) else { + let Ok(v) = Reflect::get(global().as_ref(), &JsValue::from_str(key.as_ref())) else { return None; }; v.as_string() diff --git a/veilid-wasm/src/lib.rs b/veilid-wasm/src/lib.rs index d28eeb0f..1521640c 100644 --- a/veilid-wasm/src/lib.rs +++ b/veilid-wasm/src/lib.rs @@ -79,7 +79,7 @@ pub fn unmarshall(b64: String) -> APIResult> { }) } -pub fn marshall(data: &Vec) -> String { +pub fn marshall(data: &[u8]) -> String { data_encoding::BASE64URL_NOPAD.encode(data) } @@ -116,7 +116,7 @@ where F: Future> + 'static, T: Serialize + Debug + 'static, { - future_to_promise(future.map(|res| res.map(|v| to_json(v)).map_err(|e| to_json(e)))) + future_to_promise(future.map(|res| res.map(|v| to_json(v)).map_err(to_json))) } pub fn wrap_api_future_plain(future: F) -> Promise @@ -125,14 +125,14 @@ where JsValue: From, T: 'static, { - future_to_promise(future.map(|res| res.map(|v| to_jsvalue(v)).map_err(|e| to_json(e)))) + future_to_promise(future.map(|res| res.map(|v| to_jsvalue(v)).map_err(to_json))) } pub fn wrap_api_future_void(future: F) -> Promise where F: Future> + 'static, { - future_to_promise(future.map(|res| res.map(|_| JsValue::UNDEFINED).map_err(|e| to_json(e)))) + future_to_promise(future.map(|res| res.map(|_| JsValue::UNDEFINED).map_err(to_json))) } ///////////////////////////////////////// @@ -340,7 +340,7 @@ pub fn release_routing_context(id: u32) -> i32 { if rc.remove(&id).is_none() { return 0; } - return 1; + 1 } #[wasm_bindgen()] @@ -352,8 +352,7 @@ pub fn routing_context_with_privacy(id: u32) -> u32 { let Ok(routing_context) = routing_context.clone().with_privacy() else { return 0; }; - let new_id = add_routing_context(routing_context); - new_id + add_routing_context(routing_context) } #[wasm_bindgen()] @@ -371,8 +370,7 @@ pub fn routing_context_with_custom_privacy(id: u32, safety_selection: String) -> else { return 0; }; - let new_id = add_routing_context(routing_context); - new_id + add_routing_context(routing_context) } #[wasm_bindgen()] @@ -384,8 +382,7 @@ pub fn routing_context_with_sequencing(id: u32, sequencing: String) -> u32 { return 0; }; let routing_context = routing_context.clone().with_sequencing(sequencing); - let new_id = add_routing_context(routing_context); - new_id + add_routing_context(routing_context) } #[wasm_bindgen()] @@ -561,7 +558,7 @@ pub fn routing_context_get_dht_value( pub fn routing_context_set_dht_value(id: u32, key: String, subkey: u32, data: String) -> Promise { let key: veilid_core::TypedKey = veilid_core::deserialize_json(&key).unwrap(); let data: Vec = data_encoding::BASE64URL_NOPAD - .decode(&data.as_bytes()) + .decode(data.as_bytes()) .unwrap(); wrap_api_future_json(async move { @@ -741,7 +738,7 @@ pub fn release_table_db(id: u32) -> i32 { if tdbs.remove(&id).is_none() { return 0; } - return 1; + 1 } #[wasm_bindgen()] @@ -766,7 +763,7 @@ pub fn table_db_get_column_count(id: u32) -> u32 { let Ok(cc) = table_db.clone().get_column_count() else { return 0; }; - return cc; + cc } #[wasm_bindgen()] @@ -810,8 +807,7 @@ pub fn table_db_transact(id: u32) -> u32 { return 0; }; let tdbt = table_db.clone().transact(); - let tdbtid = add_table_db_transaction(tdbt); - return tdbtid; + add_table_db_transaction(tdbt) } #[wasm_bindgen()] @@ -820,7 +816,7 @@ pub fn release_table_db_transaction(id: u32) -> i32 { if tdbts.remove(&id).is_none() { return 0; } - return 1; + 1 } #[wasm_bindgen()] diff --git a/veilid-wasm/src/veilid_client_js.rs b/veilid-wasm/src/veilid_client_js.rs index e89103cb..2b2319b7 100644 --- a/veilid-wasm/src/veilid_client_js.rs +++ b/veilid-wasm/src/veilid_client_js.rs @@ -163,12 +163,11 @@ impl VeilidClient { /// Return the cargo package version of veilid-core, in object format. pub fn version() -> VeilidVersion { let (major, minor, patch) = veilid_core::veilid_version(); - let vv = super::VeilidVersion { + super::VeilidVersion { major, minor, patch, - }; - vv + } } /// Return the cargo package version of veilid-core, in string format. diff --git a/veilid-wasm/src/veilid_crypto_js.rs b/veilid-wasm/src/veilid_crypto_js.rs index e12a1978..55f4557d 100644 --- a/veilid-wasm/src/veilid_crypto_js.rs +++ b/veilid-wasm/src/veilid_crypto_js.rs @@ -411,7 +411,7 @@ impl VeilidCrypto { veilid_core::SharedSecret::from_str(&shared_secret)?; let associated_data = associated_data - .map(|ad| unmarshall(ad)) + .map(unmarshall) .map_or(APIResult::Ok(None), |r| r.map(Some))?; let veilid_api = get_veilid_api()?; @@ -453,7 +453,7 @@ impl VeilidCrypto { veilid_core::SharedSecret::from_str(&shared_secret)?; let associated_data: Option> = associated_data - .map(|ad| unmarshall(ad)) + .map(unmarshall) .map_or(APIResult::Ok(None), |r| r.map(Some))?; let veilid_api = get_veilid_api()?; diff --git a/veilid-wasm/src/veilid_table_db_js.rs b/veilid-wasm/src/veilid_table_db_js.rs index f1fb86c3..181a43ef 100644 --- a/veilid-wasm/src/veilid_table_db_js.rs +++ b/veilid-wasm/src/veilid_table_db_js.rs @@ -23,7 +23,9 @@ impl VeilidTableDB { fn getTableDB(&self) -> APIResult { let Some(table_db) = &self.inner_table_db else { - return APIResult::Err(veilid_core::VeilidAPIError::generic("Unable to getTableDB instance. Ensure you've called openTable().")); + return APIResult::Err(veilid_core::VeilidAPIError::generic( + "Unable to getTableDB instance. Ensure you've called openTable().", + )); }; APIResult::Ok(table_db.clone()) } @@ -140,7 +142,9 @@ impl VeilidTableDBTransaction { fn getTransaction(&self) -> APIResult { let Some(transaction) = &self.inner_transaction else { - return APIResult::Err(veilid_core::VeilidAPIError::generic("Unable to getTransaction instance. inner_transaction is None.")); + return APIResult::Err(veilid_core::VeilidAPIError::generic( + "Unable to getTransaction instance. inner_transaction is None.", + )); }; APIResult::Ok(transaction.clone()) } @@ -174,3 +178,9 @@ impl VeilidTableDBTransaction { transaction.delete(col, &key) } } + +impl Default for VeilidTableDBTransaction { + fn default() -> Self { + Self::new() + } +}