Skip to content

Commit

Permalink
#107 Explicitly use trait impl in types (#108)
Browse files Browse the repository at this point in the history
Co-authored-by: Hugh Kaznowski <[email protected]>
  • Loading branch information
phughk and Hugh Kaznowski authored Feb 4, 2025
1 parent e2c0731 commit 10bacb2
Showing 1 changed file with 9 additions and 9 deletions.
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

0 comments on commit 10bacb2

Please sign in to comment.