Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 27, 2020
1 parent 9ed859a commit f46c89d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 33 deletions.
35 changes: 4 additions & 31 deletions git-transport/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl<'a> RequestWriter<'a> {
reader,
}
}
pub fn into_read(self) -> ResponseReader<'a> {
ResponseReader { reader: self.reader }
pub fn into_read(self) -> Box<dyn ExtendedBufRead + 'a> {
self.reader
}
}

Expand All @@ -122,33 +122,6 @@ impl<'a, T: io::Read> ExtendedBufRead for git_packetline::provider::ReadWithSide
}
}

impl<'a> ExtendedBufRead for ResponseReader<'a> {
fn set_progress_handler(&mut self, handle_progress: Option<HandleProgress>) {
self.reader.set_progress_handler(handle_progress)
}
}

/// A type implementing `Read` to obtain the server response.
pub struct ResponseReader<'a> {
reader: Box<dyn ExtendedBufRead + 'a>,
}

impl<'a> io::Read for ResponseReader<'a> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.reader.read(buf)
}
}

impl<'a> io::BufRead for ResponseReader<'a> {
fn fill_buf(&mut self) -> io::Result<&[u8]> {
self.reader.fill_buf()
}

fn consume(&mut self, amt: usize) {
self.reader.consume(amt)
}
}

pub type HandleProgress = Box<dyn FnMut(bool, &[u8])>;

pub(crate) struct WritePacketOnDrop<W: io::Write> {
Expand Down Expand Up @@ -214,7 +187,7 @@ pub trait TransportV2Ext {
command: &str,
capabilities: impl IntoIterator<Item = (&'a str, Option<&'a str>)>,
arguments: Option<impl IntoIterator<Item = bstr::BString>>,
) -> Result<ResponseReader, Error>;
) -> Result<Box<dyn ExtendedBufRead + '_>, Error>;
}

impl<T: Transport> TransportV2Ext for T {
Expand All @@ -223,7 +196,7 @@ impl<T: Transport> TransportV2Ext for T {
command: &str,
capabilities: impl IntoIterator<Item = (&'a str, Option<&'a str>)>,
arguments: Option<impl IntoIterator<Item = BString>>,
) -> Result<ResponseReader, Error> {
) -> Result<Box<dyn ExtendedBufRead + '_>, Error> {
let mut writer = self.request(WriteMode::OneLFTerminatedLinePerWriteCall, vec![MessageKind::Flush])?;
writer.write_all(format!("command={}", command).as_bytes())?;
for (name, value) in capabilities {
Expand Down
2 changes: 1 addition & 1 deletion git-transport/tests/client/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod connect_message {
use crate::fixture_bytes;
use bstr::ByteSlice;
use git_transport::{
client::{self, git, ExtendedBufRead, Transport, TransportV2Ext},
client::{self, git, Transport, TransportV2Ext},
Protocol, Service,
};
use std::{
Expand Down
1 change: 0 additions & 1 deletion git-transport/tests/client/http.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::fixture_bytes;
use bstr::{ByteSlice, ByteVec};
use git_transport::client::ExtendedBufRead;
use git_transport::{client, client::http, client::SetServiceResponse, client::Transport, Protocol, Service};
use std::{
cell::RefCell,
Expand Down

0 comments on commit f46c89d

Please sign in to comment.