mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
make some code more idiomatic
This commit is contained in:
parent
d073a1c22b
commit
2a2e82efeb
2 changed files with 10 additions and 10 deletions
|
@ -68,7 +68,7 @@ where
|
|||
}
|
||||
|
||||
// fast varints modified from https://github.com/luojia65/mc-varint/blob/master/src/lib.rs#L67
|
||||
/// Read a single varint from the reader and return the value, along with the number of bytes read
|
||||
/// Read a single varint from the reader and return the value
|
||||
fn read_varint(&mut self) -> Result<i32, BufReadError> {
|
||||
let mut buffer = [0];
|
||||
let mut ans = 0;
|
||||
|
@ -77,7 +77,7 @@ where
|
|||
.map_err(|_| BufReadError::InvalidVarInt)?;
|
||||
ans |= ((buffer[0] & 0b0111_1111) as i32) << (7 * i);
|
||||
if buffer[0] & 0b1000_0000 == 0 {
|
||||
return Ok(ans);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(ans)
|
||||
|
|
|
@ -18,7 +18,7 @@ fn read_string(stream: &mut impl Read) -> Result<String, Error> {
|
|||
impl Tag {
|
||||
#[inline]
|
||||
fn read_known(stream: &mut impl Read, id: u8) -> Result<Tag, Error> {
|
||||
let tag = match id {
|
||||
Ok(match id {
|
||||
// Signifies the end of a TAG_Compound. It is only ever used inside
|
||||
// a TAG_Compound, and is not named despite being in a TAG_Compound
|
||||
0 => Tag::End,
|
||||
|
@ -104,8 +104,7 @@ impl Tag {
|
|||
Tag::LongArray(longs)
|
||||
}
|
||||
_ => return Err(Error::InvalidTagType(id)),
|
||||
};
|
||||
Ok(tag)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn read(stream: &mut impl Read) -> Result<Tag, Error> {
|
||||
|
@ -137,10 +136,11 @@ impl Tag {
|
|||
|
||||
impl McBufReadable for Tag {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> {
|
||||
match Tag::read(buf) {
|
||||
Ok(r) => Ok(r),
|
||||
// Err(e) => Err(e.to_string()),
|
||||
Err(e) => Err(e.to_string()).unwrap(),
|
||||
}
|
||||
Ok(Tag::read(buf)?)
|
||||
}
|
||||
}
|
||||
impl From<Error> for BufReadError {
|
||||
fn from(e: Error) -> Self {
|
||||
BufReadError::Custom(e.to_string())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue