Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
geieredgar authored and djc committed Feb 12, 2021
1 parent a016715 commit 3acf0f2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
12 changes: 5 additions & 7 deletions interop/src/qif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,13 @@ impl InputType {
&& ancestors[2] == OsStr::new("encoded")
}

fn is_encoded_dir(path: &Path) -> Result<bool> {
fn is_encoded_dir(path: &Path) -> bool {
if !path.is_dir() {
return Ok(false);
return false;
}

Ok(
path.file_name().unwrap_or_default() == OsStr::new("encoded")
|| path.file_name().unwrap_or_default() == OsStr::new("qpack-05"),
)
path.file_name().unwrap_or_default() == OsStr::new("encoded")
|| path.file_name().unwrap_or_default() == OsStr::new("qpack-05")
}

fn is_qif_dir(path: &Path) -> Result<bool> {
Expand Down Expand Up @@ -581,7 +579,7 @@ impl InputType {
.unwrap()
.into(),
))
} else if InputType::is_encoded_dir(path)? {
} else if InputType::is_encoded_dir(path) {
println!("encoder dir");
InputType::EncodedDir(EncodedDir(path.to_path_buf()))
} else if InputType::is_qif_dir(path)? {
Expand Down
6 changes: 3 additions & 3 deletions quinn-h3/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
connection::ConnectionRef,
frame::FrameStream,
proto::{
frame::{DataFrame, FrameHeader, HeadersFrame, HttpFrame, IntoPayload},
frame::{AsPayload, DataFrame, FrameHeader, HeadersFrame, HttpFrame},
headers::Header,
ErrorCode,
},
Expand Down Expand Up @@ -191,7 +191,7 @@ enum WriteFrameState {

impl<F> WriteFrame<F>
where
F: FrameHeader + IntoPayload,
F: FrameHeader + AsPayload,
{
pub(crate) fn new(frame: F) -> Self {
let mut buf = [0u8; VarInt::MAX_SIZE * 2];
Expand Down Expand Up @@ -230,7 +230,7 @@ where
self.state = WriteFrameState::Payload;
}
WriteFrameState::Payload => {
let p = self.frame.into_payload();
let p = self.frame.as_payload();
match ready!(send.write(p.chunk()).poll_unpin(cx)) {
Err(e) => return Poll::Ready(Err(e)),
Ok(wrote) => {
Expand Down
20 changes: 10 additions & 10 deletions quinn-h3/src/proto/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl HttpFrame {
Type::DATA => Ok(HttpFrame::Data(DataFrame {
payload: payload.copy_to_bytes(payload.remaining()),
})),
Type::HEADERS => Ok(HttpFrame::Headers(HeadersFrame::decode(&mut payload)?)),
Type::HEADERS => Ok(HttpFrame::Headers(HeadersFrame::decode(&mut payload))),
Type::SETTINGS => Ok(HttpFrame::Settings(SettingsFrame::decode(&mut payload)?)),
Type::CANCEL_PUSH => Ok(HttpFrame::CancelPush(payload.get_var()?)),
Type::PUSH_PROMISE => Ok(HttpFrame::PushPromise(PushPromiseFrame::decode(
Expand Down Expand Up @@ -164,8 +164,8 @@ pub(crate) trait FrameHeader {
}
}

pub(crate) trait IntoPayload {
fn into_payload(&mut self) -> &mut dyn Buf;
pub(crate) trait AsPayload {
fn as_payload(&mut self) -> &mut dyn Buf;
}

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -193,11 +193,11 @@ where
}
}

impl<P> IntoPayload for DataFrame<P>
impl<P> AsPayload for DataFrame<P>
where
P: Buf,
{
fn into_payload(&mut self) -> &mut dyn Buf {
fn as_payload(&mut self) -> &mut dyn Buf {
&mut self.payload
}
}
Expand Down Expand Up @@ -247,10 +247,10 @@ impl FrameHeader for HeadersFrame {
}

impl HeadersFrame {
fn decode<B: Buf>(buf: &mut B) -> Result<Self, UnexpectedEnd> {
Ok(HeadersFrame {
fn decode<B: Buf>(buf: &mut B) -> Self {
HeadersFrame {
encoded: buf.copy_to_bytes(buf.remaining()),
})
}
}

pub fn encode<B: BufMut>(&self, buf: &mut B) {
Expand All @@ -259,8 +259,8 @@ impl HeadersFrame {
}
}

impl IntoPayload for HeadersFrame {
fn into_payload(&mut self) -> &mut dyn Buf {
impl AsPayload for HeadersFrame {
fn as_payload(&mut self) -> &mut dyn Buf {
&mut self.encoded
}
}
Expand Down
12 changes: 5 additions & 7 deletions quinn-h3/src/qpack/prefix_string/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl HuffmanEncoder {
self.buffer.extend(iter::repeat(255).take(forward));
}

fn put(&mut self, code: u8) -> Result<(), Error> {
fn put(&mut self, code: u8) {
let encode_value = &HPACK_STRING[code as usize];

self.ensure_free_space(encode_value.bit_count);
Expand All @@ -65,12 +65,10 @@ impl HuffmanEncoder {

write_bits(&mut self.buffer, &self.buffer_pos, part)
}

Ok(())
}

fn ends(self) -> Result<Vec<u8>, Error> {
Ok(self.buffer)
fn ends(self) -> Vec<u8> {
self.buffer
}
}

Expand Down Expand Up @@ -389,9 +387,9 @@ impl HpackStringEncode for Vec<u8> {
fn hpack_encode(&self) -> Result<Vec<u8>, Error> {
let mut encoder = HuffmanEncoder::new();
for code in self {
encoder.put(*code)?;
encoder.put(*code);
}
encoder.ends()
Ok(encoder.ends())
}
}

Expand Down
1 change: 1 addition & 0 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,7 @@ where
result
}

#[allow(clippy::suspicious_operation_groupings)]
fn peer_completed_address_validation(&self) -> bool {
if self.side.is_server() || self.state.is_closed() {
return true;
Expand Down

0 comments on commit 3acf0f2

Please sign in to comment.