From 953eb92e982c32a2d9018fd92c6bc4298b1c0399 Mon Sep 17 00:00:00 2001 From: DarkSky <25152247+darkskygit@users.noreply.github.com> Date: Wed, 10 Jul 2024 11:51:49 +0800 Subject: [PATCH] chore: bump toolchain & fix lints (#44) --- .github/workflows/y-octo-node.yml | 8 ++--- .github/workflows/y-octo.yml | 2 +- Cargo.toml | 4 +-- package.json | 4 +-- rust-toolchain | 2 +- y-octo/Cargo.toml | 8 +++++ y-octo/src/doc/codec/any.rs | 53 +++++++++++++++++++++---------- y-octo/src/doc/common/somr.rs | 1 + y-octo/src/doc/types/text.rs | 20 ++++++------ y-octo/src/doc/types/value.rs | 12 ++++--- y-octo/src/protocol/awareness.rs | 2 ++ 11 files changed, 74 insertions(+), 42 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/.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 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/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 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/doc/codec/any.rs b/y-octo/src/doc/codec/any.rs index 03e20a8..adaa31b 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; @@ -363,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), @@ -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/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>; } 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, ""), } } } diff --git a/y-octo/src/protocol/awareness.rs b/y-octo/src/protocol/awareness.rs index 5cd397e..d5afe8e 100644 --- a/y-octo/src/protocol/awareness.rs +++ b/y-octo/src/protocol/awareness.rs @@ -92,7 +92,9 @@ 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,