Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#107 Explicitly use trait impl in types #108

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/protocol/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<T: NewType<bool>> Encoder<&T> for Boolean {

impl<T: NewType<bool>> Decoder<T> for Boolean {
fn decode<B: ByteBuf>(&self, buf: &mut B) -> Result<T> {
Ok((buf.try_get_u8()? != 0).into())
Ok((ByteBuf::try_get_u8(buf)? != 0).into())
}
}

Expand All @@ -72,7 +72,7 @@ macro_rules! define_simple_ints {

impl<T: NewType<$t>> Decoder<T> for $name {
fn decode<B: ByteBuf>(&self, buf: &mut B) -> Result<T> {
Ok(buf.$get()?.into())
Ok(ByteBuf::$get(buf)?.into())
}
}

Expand Down Expand Up @@ -121,7 +121,7 @@ impl<T: NewType<u32>> Decoder<T> for UnsignedVarInt {
fn decode<B: ByteBuf>(&self, buf: &mut B) -> Result<T> {
let mut value = 0;
for i in 0..5 {
let b = buf.try_get_u8()? as u32;
let b = ByteBuf::try_get_u8(buf)? as u32;
value |= (b & 0x7F) << (i * 7);
if b < 0x80 {
break;
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<T: NewType<u64>> Decoder<T> for UnsignedVarLong {
fn decode<B: ByteBuf>(&self, buf: &mut B) -> Result<T> {
let mut value = 0;
for i in 0..10 {
let b = buf.try_get_u8()? as u64;
let b = ByteBuf::try_get_u8(buf)? as u64;
value |= (b & 0x7F) << (i * 7);
if b < 0x80 {
break;
Expand Down Expand Up @@ -252,7 +252,7 @@ impl<T: NewType<uuid::Uuid>> Encoder<&T> for Uuid {
impl<T: NewType<uuid::Uuid>> Decoder<T> for Uuid {
fn decode<B: ByteBuf>(&self, buf: &mut B) -> Result<T> {
let mut result = [0; 16];
buf.try_copy_to_slice(&mut result)?;
ByteBuf::try_copy_to_slice(buf, &mut result)?;
Ok(uuid::Uuid::from_bytes(result).into())
}
}
Expand Down Expand Up @@ -360,7 +360,7 @@ impl Decoder<Option<StdString>> for String {
-1 => Ok(None),
n if n >= 0 => {
let mut strbuf = vec![0; n as usize];
buf.try_copy_to_slice(&mut strbuf)?;
ByteBuf::try_copy_to_slice(buf, &mut strbuf)?;
Ok(Some(std::string::String::from_utf8(strbuf)?))
}
n => {
Expand Down Expand Up @@ -512,7 +512,7 @@ impl Decoder<Option<StdString>> for CompactString {
0 => Ok(None),
n => {
let mut strbuf = vec![0; (n - 1) as usize];
buf.try_copy_to_slice(&mut strbuf)?;
ByteBuf::try_copy_to_slice(buf, &mut strbuf)?;
Ok(Some(std::string::String::from_utf8(strbuf)?))
}
}
Expand Down Expand Up @@ -656,7 +656,7 @@ impl Decoder<Option<Vec<u8>>> for Bytes {
-1 => Ok(None),
n if n >= 0 => {
let mut data = vec![0; n as usize];
buf.try_copy_to_slice(&mut data)?;
ByteBuf::try_copy_to_slice(buf, &mut data)?;
Ok(Some(data))
}
n => {
Expand Down Expand Up @@ -805,7 +805,7 @@ impl Decoder<Option<Vec<u8>>> for CompactBytes {
0 => Ok(None),
n => {
let mut data = vec![0; (n - 1) as usize];
buf.try_copy_to_slice(&mut data)?;
ByteBuf::try_copy_to_slice(buf, &mut data)?;
Ok(Some(data))
}
}
Expand Down