Merge branch 'clippy-fixes' into 'main'
Clippy fixes See merge request veilid/veilid!195
This commit is contained in:
		@@ -262,7 +262,7 @@ impl AssemblyBuffer {
 | 
			
		||||
        remote_addr: SocketAddr,
 | 
			
		||||
    ) -> NetworkResult<Option<Vec<u8>>> {
 | 
			
		||||
        // If we receive a zero length frame, send it
 | 
			
		||||
        if frame.len() == 0 {
 | 
			
		||||
        if frame.is_empty() {
 | 
			
		||||
            return NetworkResult::value(Some(frame.to_vec()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -338,10 +338,8 @@ impl AssemblyBuffer {
 | 
			
		||||
 | 
			
		||||
                // If we are returning a message, see if there are any more assemblies for this peer
 | 
			
		||||
                // If not, remove the peer
 | 
			
		||||
                if out.is_some() {
 | 
			
		||||
                    if peer_messages.assemblies.len() == 0 {
 | 
			
		||||
                        e.remove();
 | 
			
		||||
                    }
 | 
			
		||||
                if out.is_some() && peer_messages.assemblies.is_empty() {
 | 
			
		||||
                    e.remove();
 | 
			
		||||
                }
 | 
			
		||||
                NetworkResult::value(out)
 | 
			
		||||
            }
 | 
			
		||||
@@ -361,7 +359,7 @@ impl AssemblyBuffer {
 | 
			
		||||
 | 
			
		||||
    /// Add framing to chunk to send to the wire
 | 
			
		||||
    fn frame_chunk(chunk: &[u8], offset: usize, message_len: usize, seq: SequenceType) -> Vec<u8> {
 | 
			
		||||
        assert!(chunk.len() > 0);
 | 
			
		||||
        assert!(!chunk.is_empty());
 | 
			
		||||
        assert!(message_len <= MAX_LEN);
 | 
			
		||||
        assert!(offset + chunk.len() <= message_len);
 | 
			
		||||
 | 
			
		||||
@@ -403,7 +401,7 @@ impl AssemblyBuffer {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Do not frame or split anything zero bytes long, just send it
 | 
			
		||||
        if data.len() == 0 {
 | 
			
		||||
        if data.is_empty() {
 | 
			
		||||
            return sender(data, remote_addr).await;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -432,3 +430,9 @@ impl AssemblyBuffer {
 | 
			
		||||
        Ok(NetworkResult::value(()))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Default for AssemblyBuffer {
 | 
			
		||||
    fn default() -> Self {
 | 
			
		||||
        Self::new()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -91,6 +91,11 @@ where
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn is_empty(&self) -> bool {
 | 
			
		||||
        let inner = self.inner.lock();
 | 
			
		||||
        inner.table.is_empty()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn len(&self) -> usize {
 | 
			
		||||
        let inner = self.inner.lock();
 | 
			
		||||
        inner.table.len()
 | 
			
		||||
@@ -154,3 +159,12 @@ where
 | 
			
		||||
        Some(AsyncTagLockGuard::new(self.clone(), tag, guard))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> Default for AsyncTagLockTable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: Hash + Eq + Clone + Debug,
 | 
			
		||||
{
 | 
			
		||||
    fn default() -> Self {
 | 
			
		||||
        Self::new()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,9 @@
 | 
			
		||||
//! * `rt-async-std` - Uses `async-std` as the async runtime
 | 
			
		||||
//! * `rt-wasm-bindgen` - When building for the `wasm32` architecture, use this to enable `wasm-bindgen-futures` as the async runtime
 | 
			
		||||
//!
 | 
			
		||||
#![deny(clippy::all)]
 | 
			
		||||
#![allow(clippy::comparison_chain, clippy::upper_case_acronyms)]
 | 
			
		||||
#![deny(unused_must_use)]
 | 
			
		||||
 | 
			
		||||
// pub mod bump_port;
 | 
			
		||||
pub mod assembly_buffer;
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ fn must_encode_path(c: u8) -> bool {
 | 
			
		||||
fn is_valid_scheme<H: AsRef<str>>(host: H) -> bool {
 | 
			
		||||
    let mut chars = host.as_ref().chars();
 | 
			
		||||
    if let Some(ch) = chars.next() {
 | 
			
		||||
        if !matches!(ch, 'A'..='Z' | 'a'..='z') {
 | 
			
		||||
        if !ch.is_ascii_alphabetic() {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
            }
 | 
			
		||||
@@ -68,29 +74,32 @@ cfg_if! {
 | 
			
		||||
            let show_month = show_year || now.month() != date.month();
 | 
			
		||||
            let show_date = show_month || now.day() != date.day();
 | 
			
		||||
 | 
			
		||||
            let s_year = if show_year {
 | 
			
		||||
                format!("{:04}/",date.year())
 | 
			
		||||
            } else {
 | 
			
		||||
                "".to_owned()
 | 
			
		||||
            };
 | 
			
		||||
            let s_month = if show_month {
 | 
			
		||||
                format!("{:02}/",date.month())
 | 
			
		||||
            } else {
 | 
			
		||||
                "".to_owned()
 | 
			
		||||
            };
 | 
			
		||||
            let s_date = if show_date {
 | 
			
		||||
                format!("{:02}-",date.day())
 | 
			
		||||
            } else {
 | 
			
		||||
                "".to_owned()
 | 
			
		||||
            };
 | 
			
		||||
            let s_time = format!("{:02}:{:02}:{:02}.{:04}",
 | 
			
		||||
                date.hour(),
 | 
			
		||||
                date.minute(),
 | 
			
		||||
                date.second(),
 | 
			
		||||
                date.nanosecond()/1_000_000
 | 
			
		||||
            );
 | 
			
		||||
            format!("{}{}{}{}",
 | 
			
		||||
                if show_year {
 | 
			
		||||
                    format!("{:04}/",date.year())
 | 
			
		||||
                } else {
 | 
			
		||||
                    "".to_owned()
 | 
			
		||||
                },
 | 
			
		||||
                if show_month {
 | 
			
		||||
                    format!("{:02}/",date.month())
 | 
			
		||||
                } else {
 | 
			
		||||
                    "".to_owned()
 | 
			
		||||
                },
 | 
			
		||||
                if show_date {
 | 
			
		||||
                    format!("{:02}-",date.day())
 | 
			
		||||
                } else {
 | 
			
		||||
                    "".to_owned()
 | 
			
		||||
                },
 | 
			
		||||
                format!("{:02}:{:02}:{:02}.{:04}",
 | 
			
		||||
                        date.hour(),
 | 
			
		||||
                        date.minute(),
 | 
			
		||||
                        date.second(),
 | 
			
		||||
                        date.nanosecond()/1_000_000
 | 
			
		||||
                ))
 | 
			
		||||
 | 
			
		||||
                s_year,
 | 
			
		||||
                s_month,
 | 
			
		||||
                s_date,
 | 
			
		||||
                s_time)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -242,7 +242,7 @@ pub fn compatible_unspecified_socket_addr(socket_addr: &SocketAddr) -> SocketAdd
 | 
			
		||||
pub fn listen_address_to_socket_addrs(listen_address: &str) -> Result<Vec<SocketAddr>, String> {
 | 
			
		||||
    // If no address is specified, but the port is, use ipv4 and ipv6 unspecified
 | 
			
		||||
    // If the address is specified, only use the specified port and fail otherwise
 | 
			
		||||
    let ip_addrs = vec![
 | 
			
		||||
    let ip_addrs = [
 | 
			
		||||
        IpAddr::V4(Ipv4Addr::UNSPECIFIED),
 | 
			
		||||
        IpAddr::V6(Ipv6Addr::UNSPECIFIED),
 | 
			
		||||
    ];
 | 
			
		||||
@@ -335,6 +335,8 @@ cfg_if::cfg_if! {
 | 
			
		||||
#[repr(C, align(8))]
 | 
			
		||||
struct AlignToEight([u8; 8]);
 | 
			
		||||
 | 
			
		||||
/// # Safety
 | 
			
		||||
/// Ensure you immediately initialize this vector as it could contain sensitive data
 | 
			
		||||
pub unsafe fn aligned_8_u8_vec_uninit(n_bytes: usize) -> Vec<u8> {
 | 
			
		||||
    let n_units = (n_bytes + mem::size_of::<AlignToEight>() - 1) / mem::size_of::<AlignToEight>();
 | 
			
		||||
    let mut aligned: Vec<AlignToEight> = Vec::with_capacity(n_units);
 | 
			
		||||
@@ -349,12 +351,14 @@ pub unsafe fn aligned_8_u8_vec_uninit(n_bytes: usize) -> Vec<u8> {
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// # Safety
 | 
			
		||||
/// Ensure you immediately initialize this vector as it could contain sensitive data
 | 
			
		||||
pub unsafe fn unaligned_u8_vec_uninit(n_bytes: usize) -> Vec<u8> {
 | 
			
		||||
    let mut unaligned: Vec<u8> = Vec::with_capacity(n_bytes);
 | 
			
		||||
    let ptr = unaligned.as_mut_ptr();
 | 
			
		||||
    mem::forget(unaligned);
 | 
			
		||||
 | 
			
		||||
    Vec::from_raw_parts(ptr as *mut u8, n_bytes, n_bytes)
 | 
			
		||||
    Vec::from_raw_parts(ptr, n_bytes, n_bytes)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn debug_backtrace() -> String {
 | 
			
		||||
 
 | 
			
		||||
@@ -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<K: AsRef<str>>(key: K) -> Option<String> {
 | 
			
		||||
    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()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user