From 2986ecfb96f51391eddf10530fe9616eeeb763b9 Mon Sep 17 00:00:00 2001 From: shenjack-mac <3695888@qq.com> Date: Thu, 3 Aug 2023 12:16:34 +0800 Subject: [PATCH] docs --- src/data.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/data.rs b/src/data.rs index 0b091a0..9cdeabd 100644 --- a/src/data.rs +++ b/src/data.rs @@ -12,6 +12,7 @@ pub type StringLength = u32; /// Reader pub type Reader<'a> = Cursor<&'a [u8]>; +#[allow(unused)] #[derive(Debug, Clone)] pub enum NbtItem { Value(NbtValue), @@ -79,6 +80,8 @@ add_impl!(Vec, bool, 0x07); add_impl!(Vec, i32, 0x0B); add_impl!(Vec, i64, 0x0C); +/// 给 HashMap 增加 NbtListTrait +/// 用作待会儿的 NbtCompound impl NbtListTrait for HashMap, NbtItem> where T: Clone + NbtListTrait, @@ -94,6 +97,8 @@ where fn get_name(&self, name: &str) -> Option { self.get(name).cloned() } } +/// 给 Vec 增加 NbtListTrait +/// 用作待会儿的 NbtList impl NbtListTrait for Vec> where T: Clone + NbtListTrait, @@ -109,6 +114,7 @@ where fn get_name(&self, _: &str) -> Option { None } } +/// ByteArray impl NbtList> { /// 直接读取长度和值 不带名称 pub fn from_reader(value: &mut Reader) -> Self { @@ -123,6 +129,7 @@ impl NbtList> { } } +/// IntArray impl NbtList> { /// 直接读取长度和值 不带名称 pub fn from_reader(value: &mut Reader) -> Self { @@ -137,6 +144,7 @@ impl NbtList> { } } +/// LongArray impl NbtList> { /// 直接读取长度和值 不带名称 pub fn from_reader(value: &mut Reader) -> Self { @@ -240,7 +248,7 @@ impl NbtValue { /// 直接读取 pub fn from_string(value: &mut Reader) -> Self { - let len: StringLength = Self::from_i32(value).as_i32().unwrap() as u32; + let len: StringLength = Self::from_i32(value).as_i32().unwrap() as StringLength; let mut buff = vec![0_u8; len as usize]; _ = value.read(&mut buff).unwrap(); Self::NbtString(Arc::from(String::from_utf8(buff).unwrap()))