aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-07-17 00:02:10 -0400
committerJesse Luehrs <doy@tozt.net>2020-07-17 00:02:10 -0400
commite743ece128ee8b78a094d3dd68243759ca4c0758 (patch)
tree60f64fb8f486f564b6029c955b83423cef62f042
parentb2511d2a57e3b7f676dd389b7930b7c0af834d29 (diff)
downloadpty-process-e743ece128ee8b78a094d3dd68243759ca4c0758.tar.gz
pty-process-e743ece128ee8b78a094d3dd68243759ca4c0758.zip
pass by reference
-rw-r--r--examples/basic.rs2
-rw-r--r--src/command.rs8
-rw-r--r--src/pty.rs6
3 files changed, 10 insertions, 6 deletions
diff --git a/examples/basic.rs b/examples/basic.rs
index 2f71bb4..15cc137 100644
--- a/examples/basic.rs
+++ b/examples/basic.rs
@@ -10,7 +10,7 @@ fn main() {
"-E",
"my @size = GetTerminalSize; say for @size",
])
- .spawn_pty(Some(pty_process::Size::new(24, 80)))
+ .spawn_pty(Some(&pty_process::Size::new(24, 80)))
.unwrap();
let mut buf = [0_u8; 4096];
let pty = child.pty().as_raw_fd();
diff --git a/src/command.rs b/src/command.rs
index f5357d2..10de48e 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -4,11 +4,15 @@ use std::os::unix::io::{AsRawFd as _, FromRawFd as _};
use std::os::unix::process::CommandExt as _;
pub trait Command {
- fn spawn_pty(&mut self, size: Option<crate::pty::Size>) -> Result<Child>;
+ fn spawn_pty(&mut self, size: Option<&crate::pty::Size>)
+ -> Result<Child>;
}
impl Command for std::process::Command {
- fn spawn_pty(&mut self, size: Option<crate::pty::Size>) -> Result<Child> {
+ fn spawn_pty(
+ &mut self,
+ size: Option<&crate::pty::Size>,
+ ) -> Result<Child> {
let pty = crate::pty::Pty::new()?;
let pts = pty.pts(size)?;
diff --git a/src/pty.rs b/src/pty.rs
index 39ffd70..383e81d 100644
--- a/src/pty.rs
+++ b/src/pty.rs
@@ -34,8 +34,8 @@ impl Size {
}
}
-impl From<Size> for nix::pty::Winsize {
- fn from(size: Size) -> Self {
+impl From<&Size> for nix::pty::Winsize {
+ fn from(size: &Size) -> Self {
Self {
ws_row: size.row,
ws_col: size.col,
@@ -78,7 +78,7 @@ impl Pty {
&self.pt
}
- pub fn pts(&self, size: Option<Size>) -> Result<std::fs::File> {
+ pub fn pts(&self, size: Option<&Size>) -> Result<std::fs::File> {
let fh = std::fs::OpenOptions::new()
.read(true)
.write(true)