From b29960ff437ecbce9f48ac106c1a9210f95e4888 Mon Sep 17 00:00:00 2001 From: DarkSky Date: Tue, 9 Jul 2024 17:18:09 +0800 Subject: [PATCH 1/6] chore: bump toolchain --- package.json | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5837b91..760f758 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "format": "run-p format:toml format:prettier format:rs", "format:toml": "taplo format", "format:prettier": "prettier --write .", - "format:rs": "cargo +nightly-2023-08-19 fmt --all" + "format:rs": "cargo +nightly-2024-07-06 fmt --all" }, "devDependencies": { "@taplo/cli": "^0.5.2", @@ -37,7 +37,7 @@ "taplo format" ], "*.rs": [ - "cargo +nightly-2023-08-19 fmt --" + "cargo +nightly-2024-07-06 fmt --" ] }, "resolutions": { diff --git a/rust-toolchain b/rust-toolchain index 883bde3..6174fee 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.71.1 \ No newline at end of file +1.79.0 \ No newline at end of file From 1ed95363c77096e8c6de318bcadfa39ecd6abf69 Mon Sep 17 00:00:00 2001 From: DarkSky Date: Tue, 9 Jul 2024 18:05:09 +0800 Subject: [PATCH 2/6] chore: fix ci --- .github/workflows/y-octo-node.yml | 8 ++++---- y-octo/src/doc/common/somr.rs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/y-octo-node.yml b/.github/workflows/y-octo-node.yml index 1e4515d..cfc7151 100644 --- a/.github/workflows/y-octo-node.yml +++ b/.github/workflows/y-octo-node.yml @@ -19,10 +19,10 @@ jobs: fail-fast: false matrix: settings: - - target: x86_64-apple-darwin - host: macos-latest - # - target: aarch64-apple-darwin + # - target: x86_64-apple-darwin # host: macos-latest + - target: aarch64-apple-darwin + host: macos-latest - target: x86_64-pc-windows-msvc host: windows-latest # - target: aarch64-pc-windows-msvc @@ -88,7 +88,7 @@ jobs: fail-fast: false matrix: settings: - - target: x86_64-apple-darwin + - target: aarch64-apple-darwin host: macos-latest - target: x86_64-unknown-linux-gnu host: ubuntu-latest diff --git a/y-octo/src/doc/common/somr.rs b/y-octo/src/doc/common/somr.rs index 59ea278..a39cedd 100644 --- a/y-octo/src/doc/common/somr.rs +++ b/y-octo/src/doc/common/somr.rs @@ -280,6 +280,7 @@ impl From>> for Somr { } pub trait FlattenGet { + #[allow(dead_code)] fn flatten_get(&self) -> Option<&T>; } From 5d5917ac5eca595d3b7f7a043f0d2ae65085125b Mon Sep 17 00:00:00 2001 From: DarkSky Date: Tue, 9 Jul 2024 19:04:29 +0800 Subject: [PATCH 3/6] fix: nightly version --- .github/workflows/y-octo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/y-octo.yml b/.github/workflows/y-octo.yml index b3d91f6..2821232 100644 --- a/.github/workflows/y-octo.yml +++ b/.github/workflows/y-octo.yml @@ -8,7 +8,7 @@ on: branches: [main] env: - nightly: nightly-2023-08-19 + nightly: nightly-2024-07-06 # Cancels all previous workflow runs for pull requests that have not completed. # See https://docs.github.com/en/actions/using-jobs/using-concurrency From 1ab631ea462219886c1f8c4f08b087906153a0d7 Mon Sep 17 00:00:00 2001 From: DarkSky Date: Wed, 10 Jul 2024 11:02:24 +0800 Subject: [PATCH 4/6] fix: lints --- Cargo.toml | 4 ++-- y-octo/Cargo.toml | 8 ++++++++ y-octo/src/protocol/awareness.rs | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 72ad9a5..e9ad093 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ members = [ resolver = "2" [workspace.dependencies] - y-octo = { workspace = true, path = "./y-octo" } - y-octo-utils = { workspace = true, path = "./y-octo-utils" } + y-octo = { path = "./y-octo" } + y-octo-utils = { path = "./y-octo-utils" } [profile.release] codegen-units = 1 diff --git a/y-octo/Cargo.toml b/y-octo/Cargo.toml index 07a8dfb..eb4284e 100644 --- a/y-octo/Cargo.toml +++ b/y-octo/Cargo.toml @@ -39,6 +39,7 @@ thiserror = "1.0" bench = [] debug = [] large_refs = [] +serde_json = [] [target.'cfg(fuzzing)'.dependencies] arbitrary = { version = "1.3", features = ["derive"] } @@ -57,6 +58,13 @@ proptest = "1.3" proptest-derive = "0.4" yrs = "=0.16.5" +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(debug)', + 'cfg(fuzzing)', + 'cfg(loom)', +] } + [[bench]] harness = false name = "array_ops_benchmarks" diff --git a/y-octo/src/protocol/awareness.rs b/y-octo/src/protocol/awareness.rs index 5cd397e..325bea9 100644 --- a/y-octo/src/protocol/awareness.rs +++ b/y-octo/src/protocol/awareness.rs @@ -92,7 +92,10 @@ pub fn write_awareness(buffer: &mut W, clients: &AwarenessStates) -> R Ok(()) } + +// TODO(@darkskygit): impl reader/writer // awareness state message +#[allow(dead_code)] #[derive(Debug, PartialEq)] pub struct AwarenessMessage { clients: AwarenessStates, From b84f08e40e225cbbaef7ad71e805b447807713d0 Mon Sep 17 00:00:00 2001 From: DarkSky Date: Wed, 10 Jul 2024 11:18:39 +0800 Subject: [PATCH 5/6] chore: fix more lint by clippy --- y-octo/src/doc/codec/any.rs | 49 +++++++++++++++++++++++++---------- y-octo/src/doc/types/text.rs | 20 +++++++------- y-octo/src/doc/types/value.rs | 12 +++++---- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/y-octo/src/doc/codec/any.rs b/y-octo/src/doc/codec/any.rs index 03e20a8..7880295 100644 --- a/y-octo/src/doc/codec/any.rs +++ b/y-octo/src/doc/codec/any.rs @@ -1,4 +1,7 @@ -use std::{fmt, ops::RangeInclusive}; +use std::{ + fmt::{self, Display}, + ops::RangeInclusive, +}; use ordered_float::OrderedFloat; @@ -515,21 +518,39 @@ impl serde::Serialize for Any { } } -impl ToString for Any { - fn to_string(&self) -> String { +impl Display for Any { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::True => "true".to_string(), - Self::False => "false".to_string(), - Self::String(s) => s.clone(), - Self::Integer(i) => i.to_string(), - Self::Float32(f) => f.to_string(), - Self::Float64(f) => f.to_string(), - Self::BigInt64(i) => i.to_string(), - // TODO: stringify other types - _ => { - debug!("any to string {:?}", self); - String::default() + Self::True => write!(f, "true"), + Self::False => write!(f, "false"), + Self::String(s) => write!(f, "\"{}\"", s), + Self::Integer(i) => write!(f, "{}", i), + Self::Float32(v) => write!(f, "{}", v), + Self::Float64(v) => write!(f, "{}", v), + Self::BigInt64(v) => write!(f, "{}", v), + Self::Object(map) => { + write!(f, "{{")?; + for (i, (key, value)) in map.iter().enumerate() { + if i > 0 { + write!(f, ", ")?; + } + write!(f, "{}: {}", key, value)?; + } + write!(f, "}}") + } + Self::Array(vec) => { + write!(f, "[")?; + for (i, value) in vec.iter().enumerate() { + if i > 0 { + write!(f, ", ")?; + } + write!(f, "{}", value)?; + } + write!(f, "]") } + Self::Binary(buf) => write!(f, "{:?}", buf), + Self::Undefined => write!(f, "undefined"), + Self::Null => write!(f, "null"), } } } diff --git a/y-octo/src/doc/types/text.rs b/y-octo/src/doc/types/text.rs index 42984aa..e701b65 100644 --- a/y-octo/src/doc/types/text.rs +++ b/y-octo/src/doc/types/text.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use super::list::ListType; use crate::{impl_type, Content, JwstCodecResult}; @@ -27,19 +29,15 @@ impl Text { } } -impl ToString for Text { - fn to_string(&self) -> String { - let mut ret = String::with_capacity(self.len() as usize); - - self.iter_item().fold(&mut ret, |ret, item| { +impl Display for Text { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.iter_item().try_for_each(|item| { if let Content::String(str) = &item.get().unwrap().content { - ret.push_str(str); + write!(f, "{}", str) + } else { + Ok(()) } - - ret - }); - - ret + }) } } diff --git a/y-octo/src/doc/types/value.rs b/y-octo/src/doc/types/value.rs index de1d5d3..53a8434 100644 --- a/y-octo/src/doc/types/value.rs +++ b/y-octo/src/doc/types/value.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use super::*; #[derive(Debug, PartialEq)] @@ -123,12 +125,12 @@ impl From for Value { } } -impl ToString for Value { - fn to_string(&self) -> String { +impl Display for Value { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Value::Any(any) => any.to_string(), - Value::Text(text) => text.to_string(), - _ => String::default(), + Value::Any(any) => write!(f, "{}", any), + Value::Text(text) => write!(f, "{}", text), + _ => write!(f, ""), } } } From 42cafe5868eaf9ed6abc4c4335d7b2be253b2770 Mon Sep 17 00:00:00 2001 From: DarkSky Date: Wed, 10 Jul 2024 11:33:07 +0800 Subject: [PATCH 6/6] chore: fix more lint --- y-octo/src/doc/codec/any.rs | 4 ++-- y-octo/src/protocol/awareness.rs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/y-octo/src/doc/codec/any.rs b/y-octo/src/doc/codec/any.rs index 7880295..adaa31b 100644 --- a/y-octo/src/doc/codec/any.rs +++ b/y-octo/src/doc/codec/any.rs @@ -366,9 +366,9 @@ impl From for Any { if n.is_f64() { Self::Float64(n.as_f64().unwrap().into()) } else if n.is_i64() { - Self::Integer(n.as_i64().unwrap() as u64) + Self::Integer(n.as_i64().unwrap() as i32) } else { - Self::Integer(n.as_u64().unwrap()) + Self::Integer(n.as_u64().unwrap() as i32) } } serde_json::Value::String(s) => Self::String(s), diff --git a/y-octo/src/protocol/awareness.rs b/y-octo/src/protocol/awareness.rs index 325bea9..d5afe8e 100644 --- a/y-octo/src/protocol/awareness.rs +++ b/y-octo/src/protocol/awareness.rs @@ -92,7 +92,6 @@ pub fn write_awareness(buffer: &mut W, clients: &AwarenessStates) -> R Ok(()) } - // TODO(@darkskygit): impl reader/writer // awareness state message #[allow(dead_code)]