Skip to content

Commit

Permalink
Merge pull request #21 from tesaguri/stream-pinned-methods
Browse files Browse the repository at this point in the history
Add `TimeoutConnectorStream::{set_read_timeout_pinned,set_write_timeout_pinned,get_pin_mut}`
  • Loading branch information
hjr3 authored Jan 2, 2021
2 parents a85ff3d + 33947b1 commit f2ba820
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"
hyper = { version = "0.14.2", features = ["client"] }
pin-project-lite = "0.2"
tokio = "1.0.0"
tokio-io-timeout = "1.0.1"
tokio-io-timeout = "1.1.0"

[dev-dependencies]
hyper = { version = "0.14", features = ["client", "http1", "tcp"] }
Expand Down
34 changes: 32 additions & 2 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,48 @@ where

/// Sets the read timeout.
///
/// This will reset any pending read timeout.
/// This can only be used before the stream is pinned; use
/// [`set_read_timeout_pinned`](Self::set_read_timeout_pinned) otherwise.
pub fn set_read_timeout(&mut self, timeout: Option<Duration>) {
self.stream.set_read_timeout(timeout)
}

/// Sets the read timeout.
///
/// This will reset any pending read timeout. Use
/// [`set_read_timeout`](Self::set_read_timeout) instead if the stream has not yet been pinned.
pub fn set_read_timeout_pinned(self: Pin<&mut Self>, timeout: Option<Duration>) {
self.project()
.stream
.as_mut()
.set_read_timeout_pinned(timeout)
}

/// Returns the current write timeout.
pub fn write_timeout(&self) -> Option<Duration> {
self.stream.write_timeout()
}

/// Sets the write timeout.
///
/// This will reset any pending write timeout.
/// This can only be used before the stream is pinned; use
/// [`set_write_timeout_pinned`](Self::set_write_timeout_pinned) otherwise.
pub fn set_write_timeout(&mut self, timeout: Option<Duration>) {
self.stream.set_write_timeout(timeout)
}

/// Sets the write timeout.
///
/// This will reset any pending write timeout. Use
/// [`set_write_timeout`](Self::set_write_timeout) instead if the stream has not yet been
/// pinned.
pub fn set_write_timeout_pinned(self: Pin<&mut Self>, timeout: Option<Duration>) {
self.project()
.stream
.as_mut()
.set_write_timeout_pinned(timeout)
}

/// Returns a shared reference to the inner stream.
pub fn get_ref(&self) -> &S {
self.stream.get_ref()
Expand All @@ -63,6 +88,11 @@ where
self.stream.get_mut()
}

/// Returns a pinned mutable reference to the inner stream.
pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut S> {
self.project().stream.get_pin_mut()
}

/// Consumes the stream, returning the inner stream.
pub fn into_inner(self) -> S {
self.stream.into_inner()
Expand Down

0 comments on commit f2ba820

Please sign in to comment.