Skip to content

Commit

Permalink
Downgrade &mut self references to &self in Channel methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlevl committed Sep 21, 2023
1 parent 1de464f commit 9c60f82
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions russh/src/channels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Channel<S> {
/// Request a pseudo-terminal with the given characteristics.
#[allow(clippy::too_many_arguments)] // length checked
pub async fn request_pty(
&mut self,
&self,
want_reply: bool,
term: &str,
col_width: u32,
Expand All @@ -188,7 +188,7 @@ impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Channel<S> {
}

/// Request a remote shell.
pub async fn request_shell(&mut self, want_reply: bool) -> Result<(), Error> {
pub async fn request_shell(&self, want_reply: bool) -> Result<(), Error> {
self.send_msg(ChannelMsg::RequestShell { want_reply })
.await?;
Ok(())
Expand All @@ -197,11 +197,7 @@ impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Channel<S> {
/// Execute a remote program (will be passed to a shell). This can
/// be used to implement scp (by calling a remote scp and
/// tunneling to its standard input).
pub async fn exec<A: Into<Vec<u8>>>(
&mut self,
want_reply: bool,
command: A,
) -> Result<(), Error> {
pub async fn exec<A: Into<Vec<u8>>>(&self, want_reply: bool, command: A) -> Result<(), Error> {
self.send_msg(ChannelMsg::Exec {
want_reply,
command: command.into(),
Expand All @@ -211,14 +207,14 @@ impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Channel<S> {
}

/// Signal a remote process.
pub async fn signal(&mut self, signal: Sig) -> Result<(), Error> {
pub async fn signal(&self, signal: Sig) -> Result<(), Error> {
self.send_msg(ChannelMsg::Signal { signal }).await?;
Ok(())
}

/// Request the start of a subsystem with the given name.
pub async fn request_subsystem<A: Into<String>>(
&mut self,
&self,
want_reply: bool,
name: A,
) -> Result<(), Error> {
Expand All @@ -235,7 +231,7 @@ impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Channel<S> {
/// [RFC4254](https://tools.ietf.org/html/rfc4254#section-6.3.1)
/// for security issues related to cookies.
pub async fn request_x11<A: Into<String>, B: Into<String>>(
&mut self,
&self,
want_reply: bool,
single_connection: bool,
x11_authentication_protocol: A,
Expand All @@ -255,7 +251,7 @@ impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Channel<S> {

/// Set a remote environment variable.
pub async fn set_env<A: Into<String>, B: Into<String>>(
&mut self,
&self,
want_reply: bool,
variable_name: A,
variable_value: B,
Expand All @@ -271,7 +267,7 @@ impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Channel<S> {

/// Inform the server that our window size has changed.
pub async fn window_change(
&mut self,
&self,
col_width: u32,
row_height: u32,
pix_width: u32,
Expand All @@ -288,30 +284,30 @@ impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Channel<S> {
}

/// Inform the server that we will accept agent forwarding channels
pub async fn agent_forward(&mut self, want_reply: bool) -> Result<(), Error> {
pub async fn agent_forward(&self, want_reply: bool) -> Result<(), Error> {
self.send_msg(ChannelMsg::AgentForward { want_reply })
.await?;
Ok(())
}

/// Send data to a channel.
pub async fn data<R: tokio::io::AsyncRead + Unpin>(&mut self, data: R) -> Result<(), Error> {
pub async fn data<R: tokio::io::AsyncRead + Unpin>(&self, data: R) -> Result<(), Error> {
self.send_data(None, data).await
}

/// Send data to a channel. The number of bytes added to the
/// "sending pipeline" (to be processed by the event loop) is
/// returned.
pub async fn extended_data<R: tokio::io::AsyncRead + Unpin>(
&mut self,
&self,
ext: u32,
data: R,
) -> Result<(), Error> {
self.send_data(Some(ext), data).await
}

async fn send_data<R: tokio::io::AsyncRead + Unpin>(
&mut self,
&self,
ext: Option<u32>,
mut data: R,
) -> Result<(), Error> {
Expand All @@ -322,7 +318,7 @@ impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Channel<S> {
Ok(())
}

pub async fn eof(&mut self) -> Result<(), Error> {
pub async fn eof(&self) -> Result<(), Error> {
self.send_msg(ChannelMsg::Eof).await?;
Ok(())
}
Expand Down

0 comments on commit 9c60f82

Please sign in to comment.