diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c27d6fa..b197ea2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -7,6 +7,7 @@ on: env: CARGO_TERM_COLOR: always CARGO_INCREMENTAL: 0 + RUSTFLAGS: "-D warnings" permissions: checks: write @@ -29,8 +30,12 @@ jobs: toolchain: nightly components: clippy, miri, rustfmt - name: Clippy - uses: auguwu/clippy-action@master - with: - token: ${{ secrets.GITHUB_TOKEN }} + run: cargo clippy --verbose --tests + - name: Miri Setup + run: cargo miri setup + - name: Miri Test + run: cargo miri test + - name: Rustfmt + run: cargo fmt --all -- --check - name: Spell Check Repo uses: crate-ci/typos@master diff --git a/Cargo.lock b/Cargo.lock index 2784f96..f235447 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,7 +85,7 @@ checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" [[package]] name = "minecraft_data" -version = "2.2.0+1.21.11" +version = "3.0.0+1.21.11" dependencies = [ "itoa", "mser", @@ -95,14 +95,14 @@ dependencies = [ [[package]] name = "mser" -version = "2.2.0" +version = "3.0.0" dependencies = [ "uuid", ] [[package]] name = "mser_macro" -version = "2.2.0" +version = "3.0.0" dependencies = [ "itoa", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index a3ee0de..16f9565 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,9 @@ repository = "https://github.com/hayanesuru/minecraft" edition = "2024" [workspace.dependencies] -mser = { path = "haya_ser", version = "2.2", default-features = false } -mser_macro = { path = "haya_ser_macro", version = "2.2", default-features = false } -minecraft_data = { path = "haya_data", version = "2.2", default-features = false } +mser = { path = "haya_ser", version = "3.0", default-features = false } +mser_macro = { path = "haya_ser_macro", version = "3.0", default-features = false } +minecraft_data = { path = "haya_data", version = "3.0", default-features = false } haya_nbt = { path = "haya_nbt", version = "0.1" } haya_str = { path = "haya_str", version = "0.1" } haya_ident = { path = "haya_ident", version = "0.1" } diff --git a/haya_data/Cargo.toml b/haya_data/Cargo.toml index 32f6189..2739490 100644 --- a/haya_data/Cargo.toml +++ b/haya_data/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "minecraft_data" -version = "2.2.0+1.21.11" +version = "3.0.0+1.21.11" description = "minecraft data" edition.workspace = true authors.workspace = true diff --git a/haya_protocol/src/lib.rs b/haya_protocol/src/lib.rs index 756888c..a0d2c55 100644 --- a/haya_protocol/src/lib.rs +++ b/haya_protocol/src/lib.rs @@ -247,6 +247,7 @@ impl Write for Either { #[derive(Clone, Copy, Serialize, Deserialize)] #[repr(u8)] +#[mser(varint)] pub enum KnownLinkType { ReportBug, CommunityGuidelines, @@ -292,6 +293,7 @@ pub struct ClientInformation<'a> { #[derive(Clone, Copy, Serialize, Deserialize)] #[repr(u8)] +#[mser(varint)] pub enum ChatVisibility { Full, System, @@ -310,6 +312,7 @@ impl ChatVisibility { #[derive(Clone, Copy, Serialize, Deserialize)] #[repr(u8)] +#[mser(varint)] pub enum HumanoidArm { Left, Right, @@ -333,6 +336,7 @@ impl HumanoidArm { #[derive(Clone, Copy, Serialize, Deserialize)] #[repr(u8)] +#[mser(varint)] pub enum ParticleStatus { All, Decreased, diff --git a/haya_protocol/src/serverbound.rs b/haya_protocol/src/serverbound.rs index 0023b3a..b40f117 100644 --- a/haya_protocol/src/serverbound.rs +++ b/haya_protocol/src/serverbound.rs @@ -77,6 +77,6 @@ packets! { pong = common::Pong, resource_pack = common::ResourcePack, select_known_packs = configuration::SelectKnownPacks<'_>, - custom_click_action = configuration::CustomClickAction<'_>, + custom_click_action = common::CustomClickAction<'_>, accept_code_of_conduct = configuration::AcceptCodeOfConduct, } diff --git a/haya_protocol/src/serverbound/common.rs b/haya_protocol/src/serverbound/common.rs index e464110..1e51dcc 100644 --- a/haya_protocol/src/serverbound/common.rs +++ b/haya_protocol/src/serverbound/common.rs @@ -1,5 +1,6 @@ use crate::{ClientInformation, Rest}; use haya_ident::Ident; +use haya_nbt::Tag; use uuid::Uuid; #[derive(Clone, Serialize, Deserialize)] @@ -29,6 +30,7 @@ pub struct ResourcePack { #[derive(Clone, Copy, Serialize, Deserialize)] #[repr(u8)] +#[mser(varint)] pub enum ResourcePackAction { SuccessfullyLoaded, Declined, @@ -45,3 +47,9 @@ impl ResourcePackAction { !matches!(self, Self::Accepted | Self::Downloaded) } } + +#[derive(Clone, Serialize, Deserialize)] +pub struct CustomClickAction<'a> { + pub id: Ident<'a>, + pub payload: Option, +} diff --git a/haya_protocol/src/serverbound/configuration.rs b/haya_protocol/src/serverbound/configuration.rs index 6f23346..91186e2 100644 --- a/haya_protocol/src/serverbound/configuration.rs +++ b/haya_protocol/src/serverbound/configuration.rs @@ -1,6 +1,4 @@ use crate::{KnownPack, List}; -use haya_ident::Ident; -use haya_nbt::Tag; #[derive(Clone, Serialize, Deserialize)] pub struct FinishConfiguration {} @@ -10,11 +8,5 @@ pub struct SelectKnownPacks<'a> { pub known_packs: List<'a, KnownPack<'a>, 64>, } -#[derive(Clone, Serialize, Deserialize)] -pub struct CustomClickAction<'a> { - pub id: Ident<'a>, - pub payload: Option, -} - #[derive(Clone, Serialize, Deserialize)] pub struct AcceptCodeOfConduct {} diff --git a/haya_ser/Cargo.toml b/haya_ser/Cargo.toml index a5351f9..d04cc9b 100644 --- a/haya_ser/Cargo.toml +++ b/haya_ser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mser" -version = "2.2.0" +version = "3.0.0" description = "mser" edition.workspace = true authors.workspace = true diff --git a/haya_ser/src/varint.rs b/haya_ser/src/varint.rs index b881c65..ef66c4c 100644 --- a/haya_ser/src/varint.rs +++ b/haya_ser/src/varint.rs @@ -1,6 +1,5 @@ use super::{Read, UnsafeWriter, Write}; use crate::{Error, cold_path}; -use core::slice::from_raw_parts; pub const V21MAX: usize = 0x1FFFFF; pub const V7MAX: usize = 0x7F; @@ -20,31 +19,35 @@ impl V21 { impl<'a> Read<'a> for V21 { fn read(buf: &mut &[u8]) -> Result { - let a = u8::read(buf)?; - if (a & 0x80) == 0 { - return Ok(Self(a as u32)); - } - let b = u8::read(buf)?; - if (b & 0x80) == 0 { - return Ok(Self((a & 0x7F) as u32 | ((b as u32) << 7))); - } - let c = u8::read(buf)?; - let p = (a & 0x7F) as u32 | (((b & 0x7F) as u32) << 7) | ((c as u32) << 14); - if (c & 0x80) == 0 { - return Ok(Self(p)); - } - let d = u8::read(buf)?; - if d == 0x00 { - cold_path(); - return Ok(Self(p)); - } - let e = u8::read(buf)?; - if d == 0x80 && e == 0x00 { - Ok(Self(p)) - } else { + let mut a = u8::read(buf)?; + let mut p = (a & 0x7F) as u32; + 'd: { + if a & 0x80 == 0 { + break 'd; + } + a = u8::read(buf)?; + p |= ((a & 0x7F) as u32) << 7; + if a & 0x80 == 0 { + break 'd; + } + a = u8::read(buf)?; + p |= ((a & 0x7F) as u32) << 14; + if a & 0x80 == 0 { + break 'd; + } + a = u8::read(buf)?; + if a == 0x00 { + cold_path(); + break 'd; + } + let e = u8::read(buf)?; + if a == 0x80 && e == 0x00 { + break 'd; + } cold_path(); - Err(Error) - } + return Err(Error); + }; + Ok(Self(p)) } } @@ -144,43 +147,30 @@ impl Write for V32 { impl<'a> Read<'a> for V32 { fn read(buf: &mut &[u8]) -> Result { - let a = u8::read(buf)?; - if (a & 0x80) == 0 { - return Ok(Self(a as u32)); - } - let b = u8::read(buf)?; - if (b & 0x80) == 0 { - return Ok(Self((a & 0x7F) as u32 | ((b as u32) << 7))); - } - let c = u8::read(buf)?; - if (c & 0x80) == 0 { - return Ok(Self( - (a & 0x7F) as u32 | (((b & 0x7F) as u32) << 7) | ((c as u32) << 14), - )); - } - - let d = u8::read(buf)?; - if (d & 0x80) == 0 { - return Ok(Self( - (a & 0x7F) as u32 - | (((b & 0x7F) as u32) << 7) - | (((c & 0x7F) as u32) << 14) - | ((d as u32) << 21), - )); - } - - let e = u8::read(buf)?; - if (e & 0xF0) == 0 { - return Ok(Self( - (a & 0x7F) as u32 - | (((b & 0x7F) as u32) << 7) - | (((c & 0x7F) as u32) << 14) - | (((d & 0x7F) as u32) << 21) - | ((e as u32) << 28), - )); - } - cold_path(); - Err(Error) + let mut a = u8::read(buf)?; + let mut shl = 7; + let mut p = (a & 0x7F) as u32; + 'd: { + if a & 0x80 == 0 { + break 'd; + } + for _ in 0..3 { + a = u8::read(buf)?; + p |= ((a & 0x7F) as u32) << shl; + shl += 7; + if a & 0x80 == 0 { + break 'd; + } + } + a = u8::read(buf)?; + p |= ((a & 0x0F) as u32) << shl; + if a & 0xF0 == 0 { + break 'd; + } + cold_path(); + return Err(Error); + }; + Ok(Self(p)) } } @@ -231,63 +221,45 @@ impl Write for V64 { w.write(&[n as u8 | 0x80, (n >> 7) as u8]); } else if n & 0xFFFFFFFFFFE00000 == 0 { w.write(&[n as u8 | 0x80, (n >> 7) as u8 | 0x80, (n >> 14) as u8]); - } else if n & 0xFFFFFFFFF0000000 == 0 { - w.write(&[ - n as u8 | 0x80, - (n >> 7) as u8 | 0x80, - (n >> 14) as u8 | 0x80, - (n >> 21) as u8, - ]); - } else if n & 0xFFFFFFF800000000 == 0 { - w.write(&[ - n as u8 | 0x80, - (n >> 7) as u8 | 0x80, - (n >> 14) as u8 | 0x80, - (n >> 21) as u8 | 0x80, - (n >> 28) as u8, - ]); - } else if n & 0xFFFFFC0000000000 == 0 { - w.write(&[ - n as u8 | 0x80, - (n >> 7) as u8 | 0x80, - (n >> 14) as u8 | 0x80, - (n >> 21) as u8 | 0x80, - (n >> 28) as u8 | 0x80, - (n >> 35) as u8, - ]); - } else if n & 0xFFFE000000000000 == 0 { - w.write(&[ - n as u8 | 0x80, - (n >> 7) as u8 | 0x80, - (n >> 14) as u8 | 0x80, - (n >> 21) as u8 | 0x80, - (n >> 28) as u8 | 0x80, - (n >> 35) as u8 | 0x80, - (n >> 42) as u8, - ]); - } else if n & 0xFF00000000000000 == 0 { - w.write(&[ - n as u8 | 0x80, - (n >> 7) as u8 | 0x80, - (n >> 14) as u8 | 0x80, - (n >> 21) as u8 | 0x80, - (n >> 28) as u8 | 0x80, - (n >> 35) as u8 | 0x80, - (n >> 42) as u8 | 0x80, - (n >> 49) as u8, - ]); } else { + let b = if n & 0xFFFFFFFFF0000000 == 0 { + (n >> 21) as u8 + } else { + (n >> 21) as u8 | 0x80 + }; w.write(&[ n as u8 | 0x80, (n >> 7) as u8 | 0x80, (n >> 14) as u8 | 0x80, - (n >> 21) as u8 | 0x80, - (n >> 28) as u8 | 0x80, - (n >> 35) as u8 | 0x80, - (n >> 42) as u8 | 0x80, - (n >> 49) as u8 | 0x80, - (n >> 56) as u8, + b, ]); + if n & 0xFFFFFFFFF0000000 == 0 { + } else if n & 0xFFFFFFF800000000 == 0 { + w.write_byte((n >> 28) as u8); + } else if n & 0xFFFFFC0000000000 == 0 { + w.write(&[(n >> 28) as u8 | 0x80, (n >> 35) as u8]); + } else if n & 0xFFFE000000000000 == 0 { + w.write(&[ + (n >> 28) as u8 | 0x80, + (n >> 35) as u8 | 0x80, + (n >> 42) as u8, + ]); + } else if n & 0xFF00000000000000 == 0 { + w.write(&[ + (n >> 28) as u8 | 0x80, + (n >> 35) as u8 | 0x80, + (n >> 42) as u8 | 0x80, + (n >> 49) as u8, + ]); + } else { + w.write(&[ + (n >> 28) as u8 | 0x80, + (n >> 35) as u8 | 0x80, + (n >> 42) as u8 | 0x80, + (n >> 49) as u8 | 0x80, + (n >> 56) as u8, + ]); + } } } } @@ -320,136 +292,109 @@ impl Write for V64 { impl<'a> Read<'a> for V64 { fn read(buf: &mut &[u8]) -> Result { - unsafe { - let a = u8::read(buf)?; - if (a & 0x80) == 0 { + let mut a = u8::read(buf)?; + let mut shl = 7; + let mut p = (a & 0x7F) as u64; + 'd: { + if a & 0x80 == 0 { return Ok(Self(a as u64)); } - - let b = u8::read(buf)?; - if (b & 0x80) == 0 { - return Ok(Self((a & 0x7F) as u64 | ((b as u64) << 7))); + a = u8::read(buf)?; + p |= ((a & 0x7F) as u64) << shl; + shl += 7; + if a & 0x80 == 0 { + break 'd; } - if buf.len() >= 8 { - let y = u64::from_le_bytes(*buf.as_ptr().cast::<[u8; 8]>()); + let y = unsafe { u64::from_le_bytes(*buf.as_ptr().cast::<[u8; 8]>()) }; if y & 0xFE80_8080_8080_8080 == 0x0080_8080_8080_8080 { - *buf = from_raw_parts(buf.as_ptr().add(8), buf.len() - 8); - return Ok(Self( - ((a & 0x7F) as u64) - | (((b & 0x7F) as u64) << 7) - | ((y & 0x0000_0000_0000_007F) << 14) - | ((y & 0x0000_0000_0000_7F00) << 13) - | ((y & 0x0000_0000_007F_0000) << 12) - | ((y & 0x0000_0000_7F00_0000) << 11) - | ((y & 0x0000_007F_0000_0000) << 10) - | ((y & 0x0000_7F00_0000_0000) << 9) - | ((y & 0x007F_0000_0000_0000) << 8) - | ((y & 0x0100_0000_0000_0000) << 7), - )); + *buf = unsafe { buf.get_unchecked(8..) }; + p |= ((y & 0x0000_0000_0000_007F) << 14) + | ((y & 0x0000_0000_0000_7F00) << 13) + | ((y & 0x0000_0000_007F_0000) << 12) + | ((y & 0x0000_0000_7F00_0000) << 11) + | ((y & 0x0000_007F_0000_0000) << 10) + | ((y & 0x0000_7F00_0000_0000) << 9) + | ((y & 0x007F_0000_0000_0000) << 8) + | ((y & 0x0100_0000_0000_0000) << 7); + break 'd; } } - - let c = u8::read(buf)?; - if (c & 0x80) == 0 { - return Ok(Self( - (a & 0x7F) as u64 | (((b & 0x7F) as u64) << 7) | ((c as u64) << 14), - )); - } - - let d = u8::read(buf)?; - if (d & 0x80) == 0 { - return Ok(Self( - (a & 0x7F) as u64 - | (((b & 0x7F) as u64) << 7) - | (((c & 0x7F) as u64) << 14) - | ((d as u64) << 21), - )); - } - let four = (a & 0x7F) as u64 - | (((b & 0x7F) as u64) << 7) - | (((c & 0x7F) as u64) << 14) - | (((d & 0x7F) as u64) << 21); - - let e = u8::read(buf)?; - if (e & 0x80) == 0 { - return Ok(Self(four | ((e as u64) << 28))); - } - - let f = u8::read(buf)?; - if (f & 0x80) == 0 { - return Ok(Self( - four | (((e & 0x7F) as u64) << 28) | ((f as u64) << 35), - )); - } - - let g = u8::read(buf)?; - if (g & 0x80) == 0 { - return Ok(Self( - four | (((e & 0x7F) as u64) << 28) - | (((f & 0x7F) as u64) << 35) - | ((g as u64) << 42), - )); - } - - let h = u8::read(buf)?; - if (h & 0x80) == 0 { - return Ok(Self( - four | (((e & 0x7F) as u64) << 28) - | (((f & 0x7F) as u64) << 35) - | (((g & 0x7F) as u64) << 42) - | ((h as u64) << 49), - )); - } - - let i = u8::read(buf)?; - if (i & 0x80) == 0 { - return Ok(Self( - four | (((e & 0x7F) as u64) << 28) - | (((f & 0x7F) as u64) << 35) - | (((g & 0x7F) as u64) << 42) - | (((h & 0x7F) as u64) << 49) - | ((i as u64) << 56), - )); + for _ in 0..7 { + a = u8::read(buf)?; + p |= ((a & 0x7F) as u64) << shl; + shl += 7; + if a & 0x80 == 0 { + break 'd; + } } + return Err(Error); } - - cold_path(); - Err(Error) + Ok(Self(p)) } } - -#[test] -fn test_varint() { - let mut r = 0xE3D172B05F73CBC3u64; - let mut buf = [0u8; 10]; - - for _ in 0..1000 { - r = r.wrapping_add(0xa0761d6478bd642f); - let x = (r ^ 0xe7037ed1a0b428db) as u128; - let t = (r as u128).wrapping_mul(x); - let x = (t.wrapping_shr(64) ^ t) as u64; - unsafe { - let y = V64(x); - let sz = y.len_s(); - crate::write_unchecked(buf.as_mut_ptr(), &y); - let mut sl = core::slice::from_raw_parts(buf.as_ptr(), sz); - assert_eq!(V64::read(&mut sl).unwrap(), y); - assert!(sl.is_empty()); - - let y = V32(x as u32); - crate::write_unchecked(buf.as_mut_ptr(), &y); - let sz = y.len_s(); - let mut sl = core::slice::from_raw_parts(buf.as_ptr(), sz); - assert_eq!(V32::read(&mut sl).unwrap(), y); - assert!(sl.is_empty()); - - let y = V21(x as u32 & 0x1FFFFF); - crate::write_unchecked(buf.as_mut_ptr(), &y); - let sz = y.len_s(); - let mut sl = core::slice::from_raw_parts(buf.as_ptr(), sz); - assert_eq!(V21::read(&mut sl).unwrap(), y); - assert!(sl.is_empty()); +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_write() { + let mut r = 0xE3D172B05F73CBC3u64; + let mut buf = [0u8; 10]; + let mut arr = [0; 200]; + for i in &mut arr { + r = r.wrapping_add(0xa0761d6478bd642f); + let x = (r ^ 0xe7037ed1a0b428db) as u128; + let t = (r as u128).wrapping_mul(x); + let x = (t.wrapping_shr(64) ^ t) as u64; + *i = x; + } + arr[0] = u64::MAX; + arr[1] = u32::MAX as u64; + arr[2] = V21MAX as u64; + + for x in arr { + unsafe { + let y = V64(x); + let sz = y.len_s(); + crate::write_unchecked(buf.as_mut_ptr(), &y); + let mut sl = core::slice::from_raw_parts(buf.as_ptr(), sz); + assert_eq!(V64::read(&mut sl).unwrap(), y); + assert!(sl.is_empty()); + + let y = V32(x as u32); + crate::write_unchecked(buf.as_mut_ptr(), &y); + let sz = y.len_s(); + let mut sl = core::slice::from_raw_parts(buf.as_ptr(), sz); + assert_eq!(V32::read(&mut sl).unwrap(), y); + assert!(sl.is_empty()); + + let y = V21(x as u32 & 0x1FFFFF); + crate::write_unchecked(buf.as_mut_ptr(), &y); + let sz = y.len_s(); + let mut sl = core::slice::from_raw_parts(buf.as_ptr(), sz); + assert_eq!(V21::read(&mut sl).unwrap(), y); + assert!(sl.is_empty()); + } } } + + #[test] + fn test_v21() { + let val = V21(V21MAX as u32); + let [a, b, c] = val.to_array(); + let a5 = [a, b, c | 0x80, 0x80, 0]; + let a4 = [a, b, c | 0x80, 0]; + assert_eq!(V21::read(&mut &a5[..]).unwrap(), val); + assert_eq!(V21::read(&mut &a4[..]).unwrap(), val); + assert_eq!(V21::read(&mut &[a, b, c][..]).unwrap(), val); + + let val = V21(0x1fff); + let [a, b, c] = val.to_array(); + let a5 = [a, b | 0x80, c | 0x80, 0x80, 0]; + let a4 = [a, b | 0x80, c | 0x80, 0]; + assert_eq!(V21::read(&mut &a5[..]).unwrap(), val); + assert_eq!(V21::read(&mut &a4[..]).unwrap(), val); + assert_eq!(V21::read(&mut &[a, b, c][..]).unwrap(), val); + } } diff --git a/haya_ser_macro/Cargo.toml b/haya_ser_macro/Cargo.toml index 8bfce77..4deea85 100644 --- a/haya_ser_macro/Cargo.toml +++ b/haya_ser_macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mser_macro" -version = "2.2.0" +version = "3.0.0" description = "mser_macro" authors.workspace = true readme.workspace = true @@ -13,7 +13,7 @@ categories = ["no-std"] proc-macro = true [dependencies] -syn = { version = "2", features = ["full"] } +syn = { version = "2", features = [] } quote = "1" proc-macro2 = "1" itoa = "1" diff --git a/haya_ser_macro/src/lib.rs b/haya_ser_macro/src/lib.rs index 12ba95f..2f231e2 100644 --- a/haya_ser_macro/src/lib.rs +++ b/haya_ser_macro/src/lib.rs @@ -4,13 +4,9 @@ mod deserialize; mod serialize; -// #[cfg(feature = "nbt")] -// use alloc::string::String; use proc_macro::TokenStream; use syn::{DeriveInput, parse_macro_input}; -extern crate alloc; - const V21MAX: usize = 0x1FFFFF; const V7MAX: usize = 0x7F; @@ -18,33 +14,7 @@ mod kw { syn::custom_keyword!(varint); } -// #[cfg(feature = "nbt")] -// #[proc_macro] -// pub fn compound(token: proc_macro::TokenStream) -> proc_macro::TokenStream { -// let mut data = alloc::format!("{{{token}}}"); -// let output = mser::nbt::StringifyCompound::decode(&data) -// .expect("Invalid SNBT compound") -// .0; -// data.clear(); - -// let mut data = data.into_bytes(); -// mser::write_exact(&mut data, &output); -// let mut i = itoa::Buffer::new(); -// let mut o = String::new(); -// o += "&["; -// for &x in &data { -// o += i.format(x); -// o += ", "; -// } -// if !data.is_empty() { -// o.pop(); -// o.pop(); -// } -// o += "]"; -// core::str::FromStr::from_str(&o).unwrap() -// } - -fn crate_name(input: &DeriveInput) -> Result { +fn crate_name(input: &DeriveInput) -> Result<(Option<&syn::Attribute>, syn::Path), syn::Error> { let mut find = None; for attr in input.attrs.iter() { if attr.path().is_ident("mser") { @@ -55,13 +25,16 @@ fn crate_name(input: &DeriveInput) -> Result { } } - Ok(syn::Ident::new("mser", proc_macro2::Span::call_site()).into()) + Ok(( + find, + syn::Ident::new("mser", proc_macro2::Span::call_site()).into(), + )) } #[proc_macro_derive(Serialize, attributes(mser))] pub fn serialize(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as syn::DeriveInput); - let cratename = match crate_name(&input) { + let (_attr, cratename) = match crate_name(&input) { Ok(cratename) => cratename, Err(err) => { return err.to_compile_error().into(); @@ -82,7 +55,7 @@ pub fn serialize(input: TokenStream) -> TokenStream { #[proc_macro_derive(Deserialize, attributes(mser))] pub fn deserialize(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as syn::DeriveInput); - let cratename = match crate_name(&input) { + let (_attr, cratename) = match crate_name(&input) { Ok(cratename) => cratename, Err(err) => { return err.to_compile_error().into(); diff --git a/haya_ser_macro/src/serialize.rs b/haya_ser_macro/src/serialize.rs index 88cd2d6..dd7c7b2 100644 --- a/haya_ser_macro/src/serialize.rs +++ b/haya_ser_macro/src/serialize.rs @@ -107,16 +107,8 @@ pub fn serialize_enum( Ok(()) })?; } - if attr.path().is_ident("mser") { - attr.parse_nested_meta(|meta| { - let lookahead = meta.input.lookahead1(); - if lookahead.peek(kw::varint) { - varint = true; - } - Ok(()) - })?; - } } + let repr = repr.ok_or_else(|| syn::Error::new_spanned(&input, "expected `#[repr(...)]` attribute"))?; let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();