diff --git a/Cargo.lock b/Cargo.lock index 7bc7cb20..e6a46b72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -174,9 +174,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "av1-grain" @@ -1308,9 +1308,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.173" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libfuzzer-sys" @@ -1755,6 +1755,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "ordered-float" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2c1f9f56e534ac6a9b8a4600bdf0f530fb393b5f393e7b4d03489c3cf0c3f01" +dependencies = [ + "num-traits", + "rand 0.8.5", + "serde", +] + [[package]] name = "overload" version = "0.1.1" @@ -1982,9 +1993,9 @@ dependencies = [ [[package]] name = "r-efi" -version = "5.2.0" +version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "radium" @@ -2001,6 +2012,7 @@ dependencies = [ "libc", "rand_chacha 0.3.1", "rand_core 0.6.4", + "serde", ] [[package]] @@ -2040,6 +2052,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom 0.2.16", + "serde", ] [[package]] @@ -2770,9 +2783,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1ffbcf9c6f6b99d386e7444eb608ba646ae452a36b39737deb9663b610f662" +checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" dependencies = [ "proc-macro2", "quote", @@ -3567,6 +3580,7 @@ version = "25.6.11" dependencies = [ "anyhow", "mlua", + "ordered-float 5.0.0", "parking_lot", "serde", "serde_json", @@ -3756,6 +3770,7 @@ dependencies = [ "futures", "libc", "memchr", + "ordered-float 5.0.0", "parking_lot", "percent-encoding", "ratatui", @@ -3798,18 +3813,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.25" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.25" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 9e35bad3..01e19a7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,10 +32,11 @@ foldhash = "0.1.5" futures = "0.3.31" globset = "0.4.16" indexmap = { version = "2.9.0", features = [ "serde" ] } -libc = "0.2.173" +libc = "0.2.174" lru = "0.14.0" mlua = { version = "0.10.5", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serialize" ] } objc = "0.2.7" +ordered-float = { version = "5.0.0", features = [ "serde" ] } parking_lot = "0.12.4" paste = "1.0.15" ratatui = { version = "0.29.0", features = [ "unstable-rendered-line-info" ] } diff --git a/yazi-dds/Cargo.toml b/yazi-dds/Cargo.toml index e8372836..7be073ce 100644 --- a/yazi-dds/Cargo.toml +++ b/yazi-dds/Cargo.toml @@ -20,15 +20,16 @@ yazi-macro = { path = "../yazi-macro", version = "25.6.11" } yazi-shared = { path = "../yazi-shared", version = "25.6.11" } # External dependencies -anyhow = { workspace = true } -mlua = { workspace = true } -parking_lot = { workspace = true } -serde = { workspace = true } -serde_json = { workspace = true } -tokio = { workspace = true } -tokio-stream = { workspace = true } -tokio-util = { workspace = true } -tracing = { workspace = true } +anyhow = { workspace = true } +mlua = { workspace = true } +ordered-float = { workspace = true } +parking_lot = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +tokio = { workspace = true } +tokio-stream = { workspace = true } +tokio-util = { workspace = true } +tracing = { workspace = true } [build-dependencies] vergen-gitcl = { version = "1.0.8", features = [ "build" ] } diff --git a/yazi-dds/src/sendable.rs b/yazi-dds/src/sendable.rs index 1d59f442..1be46ea6 100644 --- a/yazi-dds/src/sendable.rs +++ b/yazi-dds/src/sendable.rs @@ -1,7 +1,8 @@ use std::{any::TypeId, borrow::Cow, collections::HashMap}; use mlua::{ExternalError, IntoLua, Lua, MultiValue, Table, Value}; -use yazi_shared::{OrderedFloat, event::{Data, DataKey}, replace_cow}; +use ordered_float::OrderedFloat; +use yazi_shared::{event::{Data, DataKey}, replace_cow}; pub struct Sendable; @@ -193,7 +194,7 @@ impl Sendable { Value::Boolean(b) => DataKey::Boolean(b), Value::LightUserData(_) => Err("light userdata is not supported".into_lua_err())?, Value::Integer(i) => DataKey::Integer(i), - Value::Number(n) => DataKey::Number(OrderedFloat::new(n)), + Value::Number(n) => DataKey::Number(OrderedFloat(n)), Value::String(s) => { if let Ok(s) = s.to_str() { DataKey::String(s.to_owned().into()) @@ -235,7 +236,7 @@ impl Sendable { DataKey::Nil => Value::Nil, DataKey::Boolean(b) => Value::Boolean(*b), DataKey::Integer(i) => Value::Integer(*i), - DataKey::Number(n) => Value::Number(n.get()), + DataKey::Number(n) => Value::Number(n.0), DataKey::String(s) => Value::String(lua.create_string(s.as_ref())?), DataKey::Id(i) => yazi_binding::Id(*i).into_lua(lua)?, DataKey::Url(u) => yazi_binding::Url::new(u.clone()).into_lua(lua)?, diff --git a/yazi-shared/Cargo.toml b/yazi-shared/Cargo.toml index 7442a8e6..2acf7a3f 100644 --- a/yazi-shared/Cargo.toml +++ b/yazi-shared/Cargo.toml @@ -18,6 +18,7 @@ crossterm = { workspace = true } foldhash = { workspace = true } futures = { workspace = true } memchr = "2.7.5" +ordered-float = { workspace = true } parking_lot = { workspace = true } percent-encoding = "2.3.1" ratatui = { workspace = true } diff --git a/yazi-shared/src/event/data.rs b/yazi-shared/src/event/data.rs index a4432c5b..3b7a8109 100644 --- a/yazi-shared/src/event/data.rs +++ b/yazi-shared/src/event/data.rs @@ -1,8 +1,9 @@ use std::{any::Any, borrow::Cow, collections::HashMap}; +use ordered_float::OrderedFloat; use serde::{Deserialize, Serialize, de}; -use crate::{Id, OrderedFloat, url::{Url, UrnBuf}}; +use crate::{Id, url::{Url, UrnBuf}}; // --- Data #[derive(Debug, Serialize, Deserialize)] @@ -134,7 +135,7 @@ pub enum DataKey { Boolean(bool), #[serde(deserialize_with = "Self::deserialize_integer")] Integer(i64), - Number(OrderedFloat), + Number(OrderedFloat), String(Cow<'static, str>), Id(Id), #[serde(skip_deserializing)] diff --git a/yazi-shared/src/lib.rs b/yazi-shared/src/lib.rs index e05acf76..d3c53219 100644 --- a/yazi-shared/src/lib.rs +++ b/yazi-shared/src/lib.rs @@ -2,7 +2,7 @@ yazi_macro::mod_pub!(errors event shell translit url); -yazi_macro::mod_flat!(bytes chars condition debounce either env id layer natsort number os osstr rand ro_cell sync_cell terminal throttle time utf8); +yazi_macro::mod_flat!(bytes chars condition debounce either env id layer natsort os osstr rand ro_cell sync_cell terminal throttle time utf8); pub fn init() { LOG_LEVEL.replace(<_>::from(std::env::var("YAZI_LOG").unwrap_or_default())); diff --git a/yazi-shared/src/number.rs b/yazi-shared/src/number.rs deleted file mode 100644 index 132397e8..00000000 --- a/yazi-shared/src/number.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::hash::{Hash, Hasher}; - -use serde::{Deserialize, Deserializer, Serialize}; - -#[derive(Clone, Copy, Debug, Serialize)] -#[serde(transparent)] -pub struct OrderedFloat(f64); - -impl OrderedFloat { - #[inline] - pub fn new(t: f64) -> Self { - debug_assert!(!t.is_nan()); - Self(t) - } - - #[inline] - pub const fn get(&self) -> f64 { self.0 } -} - -impl Hash for OrderedFloat { - fn hash(&self, state: &mut H) { self.0.to_bits().hash(state) } -} - -impl PartialEq for OrderedFloat { - fn eq(&self, other: &Self) -> bool { self.0.to_bits() == other.0.to_bits() } -} - -impl Eq for OrderedFloat {} - -impl<'de> Deserialize<'de> for OrderedFloat { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let f = f64::deserialize(deserializer)?; - if f.is_nan() { - Err(serde::de::Error::custom("NaN is not a valid OrderedFloat")) - } else { - Ok(Self::new(f)) - } - } -}