…even though only a little bit can be shread soon once ExtendedBufRead is available in async. Clearly a mistake to try this one first :D
Unified · Split
| @@ -1,3 +1,14 @@ | ||
| 1 | +use std::io; | |
| 2 | + | |
| 3 | +pub use bufread_ext::{ExtendedBufRead, HandleProgress}; | |
| 4 | +pub use trait_ext::TransportV2Ext; | |
| 5 | + | |
| 6 | +pub use crate::client::RequestWriter; | |
| 7 | +use crate::{ | |
| 8 | + client::{capabilities, Capabilities, Error, Identity, MessageKind, WriteMode}, | |
| 9 | + Protocol, Service, | |
| 10 | +}; | |
| 11 | + | |
| 1 | 12 | /// |
| 2 | 13 | pub mod connect; |
| 3 | 14 | |
| @@ -9,21 +20,10 @@ pub mod git; · 5 unmodified lines | ||
| 9 | 20 | #[cfg(feature = "http-client-curl")] |
| 10 | 21 | pub mod http; |
| 11 | 22 | |
| 12 | −pub mod request; | |
| 13 | −pub use request::RequestWriter; | |
| 14 | − | |
| 15 | 23 | mod bufread_ext; |
| 16 | −pub use bufread_ext::{ExtendedBufRead, HandleProgress}; | |
| 17 | − | |
| 18 | 24 | /// |
| 19 | 25 | pub mod ssh; |
| 20 | 26 | |
| 21 | −use crate::{ | |
| 22 | − client::{capabilities, Capabilities, Error, Identity, MessageKind, WriteMode}, | |
| 23 | − Protocol, Service, | |
| 24 | −}; | |
| 25 | −use std::io; | |
| 26 | − | |
| 27 | 27 | /// The response of the [`handshake()`][Transport::handshake()] method. |
| 28 | 28 | pub struct SetServiceResponse<'a> { |
| 29 | 29 | /// The protocol the service can provide. May be different from the requested one |
| @@ -88,10 +88,12 @@ pub trait Transport { · 58 unmodified lines | ||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | mod trait_ext { |
| 91 | − use crate::client::{Error, ExtendedBufRead, MessageKind, Transport, WriteMode}; | |
| 92 | − use bstr::BString; | |
| 93 | 91 | use std::io::Write; |
| 94 | 92 | |
| 93 | + use bstr::BString; | |
| 94 | + | |
| 95 | + use crate::client::{Error, ExtendedBufRead, MessageKind, Transport, WriteMode}; | |
| 96 | + | |
| 95 | 97 | /// An extension trait to add more methods to everything implementing [`Transport`]. |
| 96 | 98 | pub trait TransportV2Ext { |
| 97 | 99 | /// Invoke a protocol V2 style `command` with given `capabilities` and optional command specific `arguments`. |
| @@ -130,14 +132,14 @@ mod trait_ext { · 32 unmodified lines | ||
| 130 | 132 | } |
| 131 | 133 | } |
| 132 | 134 | } |
| 133 | −pub use trait_ext::TransportV2Ext; | |
| 134 | 135 | |
| 135 | 136 | mod box_impl { |
| 137 | + use std::ops::{Deref, DerefMut}; | |
| 138 | + | |
| 136 | 139 | use crate::{ |
| 137 | 140 | client::{self, Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode}, |
| 138 | 141 | Protocol, Service, |
| 139 | 142 | }; |
| 140 | − use std::ops::{Deref, DerefMut}; | |
| 141 | 143 | |
| 142 | 144 | // Would be nice if the box implementation could auto-forward to all implemented traits. |
| 143 | 145 | impl<T: client::Transport + ?Sized> client::Transport for Box<T> { |
| @@ -1,11 +1,10 @@ | ||
| 1 | −#[cfg(feature = "blocking-client")] | |
| 2 | −mod blocking_io; | |
| 1 | +#[cfg(all(not(feature = "blocking-client"), feature = "async-client"))] | |
| 2 | +pub use async_io::{SetServiceResponse, Transport}; | |
| 3 | 3 | #[cfg(all(feature = "blocking-client", feature = "http-client-curl"))] |
| 4 | 4 | pub use blocking_io::http; |
| 5 | 5 | #[cfg(feature = "blocking-client")] |
| 6 | 6 | pub use blocking_io::{ |
| 7 | − connect, file, git, ssh, ExtendedBufRead, HandleProgress, RequestWriter, SetServiceResponse, Transport, | |
| 8 | − TransportV2Ext, | |
| 7 | + connect, file, git, ssh, ExtendedBufRead, HandleProgress, SetServiceResponse, Transport, TransportV2Ext, | |
| 9 | 8 | }; |
| 10 | 9 | #[cfg(feature = "blocking-client")] |
| 11 | 10 | #[doc(inline)] |
| @@ -13,13 +12,20 @@ pub use connect::connect; · 1 unmodified line | ||
| 13 | 12 | |
| 14 | 13 | #[cfg(all(not(feature = "blocking-client"), feature = "async-client"))] |
| 15 | 14 | mod async_io; |
| 16 | −#[cfg(all(not(feature = "blocking-client"), feature = "async-client"))] | |
| 17 | −pub use async_io::{SetServiceResponse, Transport}; | |
| 15 | +#[cfg(feature = "blocking-client")] | |
| 16 | +mod blocking_io; | |
| 17 | + | |
| 18 | +/// | |
| 19 | +pub mod capabilities; | |
| 20 | +#[doc(inline)] | |
| 21 | +pub use capabilities::Capabilities; | |
| 18 | 22 | |
| 19 | 23 | mod non_io_types; |
| 20 | 24 | pub use non_io_types::{Error, Identity, MessageKind, WriteMode}; |
| 21 | 25 | |
| 22 | 26 | /// |
| 23 | −pub mod capabilities; | |
| 27 | +#[cfg(feature = "blocking-client")] | |
| 28 | +pub mod request; | |
| 24 | 29 | #[doc(inline)] |
| 25 | −pub use capabilities::Capabilities; | |
| 30 | +#[cfg(feature = "blocking-client")] | |
| 31 | +pub use request::RequestWriter; | |
| @@ -20,6 +20,7 @@ impl<'a> io::Write for RequestWriter<'a> { · 19 unmodified lines | ||
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | +/// methods with bonds to IO | |
| 23 | 24 | impl<'a> RequestWriter<'a> { |
| 24 | 25 | /// Create a new instance from a `writer` (commonly a socket), a `reader` into which to transform once the |
| 25 | 26 | /// writes are finished, along with configuration for the `write_mode` and information about which message to write |
| @@ -42,12 +43,6 @@ impl<'a> RequestWriter<'a> { · 16 unmodified lines | ||
| 42 | 43 | } |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | − /// Discard the ability to write and turn this instance into the reader for obtaining the other side's response. | |
| 46 | − pub fn into_read(mut self) -> io::Result<Box<dyn ExtendedBufRead + 'a>> { | |
| 47 | − self.write_message(self.on_into_read)?; | |
| 48 | − Ok(self.reader) | |
| 49 | − } | |
| 50 | − | |
| 51 | 46 | /// Write the given message as packet line. |
| 52 | 47 | pub fn write_message(&mut self, message: MessageKind) -> io::Result<()> { |
| 53 | 48 | match message { |
| @@ -59,3 +54,12 @@ impl<'a> RequestWriter<'a> { · 5 unmodified lines | ||
| 59 | 54 | .map(|_| ()) |
| 60 | 55 | } |
| 61 | 56 | } |
| 57 | + | |
| 58 | +/// TODO: make this general | |
| 59 | +impl<'a> RequestWriter<'a> { | |
| 60 | + /// Discard the ability to write and turn this instance into the reader for obtaining the other side's response. | |
| 61 | + pub fn into_read(mut self) -> io::Result<Box<dyn ExtendedBufRead + 'a>> { | |
| 62 | + self.write_message(self.on_into_read)?; | |
| 63 | + Ok(self.reader) | |
| 64 | + } | |
| 65 | +} | |