Struct Session

Source
pub struct Session<P = OsProcess, S = OsProcessStream> { /* private fields */ }
Expand description

Session represents a spawned process and its streams. It controlls process and communication with it.

Implementations§

Source§

impl<P, S> Session<P, S>
where S: Read,

Source

pub fn new(process: P, stream: S) -> Result<Self>

Creates a new session.

Source§

impl<P, S> Session<P, S>

Source

pub fn set_expect_timeout(&mut self, expect_timeout: Option<Duration>)

Set the pty session’s expect timeout.

Source

pub fn set_expect_lazy(&mut self, lazy: bool)

Set a expect algorithm to be either gready or lazy.

Default algorithm is gready.

See Session::expect.

Source

pub fn get_stream(&self) -> &S

Get a reference to original stream.

Source

pub fn get_stream_mut(&mut self) -> &mut S

Get a mut reference to original stream.

Source

pub fn get_process(&self) -> &P

Get a reference to a process running program.

Source

pub fn get_process_mut(&mut self) -> &mut P

Get a mut reference to a process running program.

Examples found in repository?
examples/shell.rs (line 7)
5fn main() -> Result<()> {
6    let mut p = expectrl::spawn("sh")?;
7    p.get_process_mut().set_echo(true, None)?;
8
9    let mut shell = ReplSession::new(p, String::from("sh-5.1$"), Some(String::from("exit")), true);
10
11    shell.expect_prompt()?;
12
13    let output = exec(&mut shell, "echo Hello World")?;
14    println!("{:?}", output);
15
16    let output = exec(&mut shell, "echo '2 + 3' | bc")?;
17    println!("{:?}", output);
18
19    Ok(())
20}
Source§

impl<P: Healthcheck, S> Session<P, S>

Source

pub fn is_alive(&mut self) -> Result<bool, Error>

Verifies whether process is still alive.

Source§

impl<P, S: Read + NonBlocking> Session<P, S>

Source

pub fn expect<N>(&mut self, needle: N) -> Result<Captures, Error>
where N: Needle,

Expect waits until a pattern is matched.

If the method returns Ok it is guaranteed that at least 1 match was found.

The match algorthm can be either - gready - lazy

You can set one via Session::set_expect_lazy. Default version is gready.

The implications are. Imagine you use crate::Regex "\d+" to find a match. And your process outputs 123. In case of lazy approach we will match 1. Where’s in case of gready one we will match 123.

§Example
let mut p = expectrl::spawn("echo 123").unwrap();
let m = p.expect(expectrl::Regex("\\d+")).unwrap();
assert_eq!(m.get(0).unwrap(), b"123");
let mut p = expectrl::spawn("echo 123").unwrap();
p.set_expect_lazy(true);
let m = p.expect(expectrl::Regex("\\d+")).unwrap();
assert_eq!(m.get(0).unwrap(), b"1");

This behaviour is different from Session::check.

It returns an error if timeout is reached. You can specify a timeout value by Session::set_expect_timeout method.

Examples found in repository?
examples/python.rs (line 10)
4fn main() {
5    let mut p = spawn_python().unwrap();
6
7    p.execute("import platform").unwrap();
8    p.send_line("platform.node()").unwrap();
9
10    let found = p.expect(Regex(r"'.*'")).unwrap();
11
12    println!(
13        "Platform {}",
14        String::from_utf8_lossy(found.get(0).unwrap())
15    );
16}
More examples
Hide additional examples
examples/log.rs (line 10)
3fn main() -> Result<(), Error> {
4    let p = spawn("cat")?;
5    let mut p = expectrl::session::log(p, std::io::stdout())?;
6
7    #[cfg(not(feature = "async"))]
8    {
9        p.send_line("Hello World")?;
10        p.expect("Hello World")?;
11    }
12    #[cfg(feature = "async")]
13    {
14        futures_lite::future::block_on(async {
15            p.send_line("Hello World").await?;
16            p.expect("Hello World").await
17        })?;
18    }
19
20    Ok(())
21}
examples/ftp.rs (line 6)
4fn main() -> Result<(), Error> {
5    let mut p = spawn("ftp bks4-speedtest-1.tele2.net")?;
6    p.expect(Regex("Name \\(.*\\):"))?;
7    p.send_line("anonymous")?;
8    p.expect("Password")?;
9    p.send_line("test")?;
10    p.expect("ftp>")?;
11    p.send_line("cd upload")?;
12    p.expect("successfully changed.")?;
13    p.send_line("pwd")?;
14    p.expect(Regex("[0-9]+ \"/upload\""))?;
15    p.send(ControlCode::EndOfTransmission)?;
16    p.expect("Goodbye.")?;
17    Ok(())
18}
examples/expect_line.rs (lines 9-13)
4fn main() {
5    let mut session = expectrl::spawn("ls -al").expect("Can't spawn a session");
6
7    loop {
8        let m = session
9            .expect(Any::boxed(vec![
10                Box::new("\r"),
11                Box::new("\n"),
12                Box::new(Eof),
13            ]))
14            .expect("Expect failed");
15
16        println!("{:?}", String::from_utf8_lossy(m.as_bytes()));
17
18        let is_eof = m[0].is_empty();
19        if is_eof {
20            break;
21        }
22
23        if m[0] == [b'\n'] {
24            continue;
25        }
26
27        println!("{:?}", String::from_utf8_lossy(&m[0]));
28    }
29}
examples/ping.rs (line 9)
6fn main() -> Result<(), Error> {
7    let mut p = spawn_bash()?;
8    p.send_line("ping 8.8.8.8")?;
9    p.expect("bytes of data")?;
10    p.send(ControlCode::try_from("^Z").unwrap())?;
11    p.expect_prompt()?;
12    // bash writes 'ping 8.8.8.8' to stdout again to state which job was put into background
13    p.send_line("bg")?;
14    p.expect("ping 8.8.8.8")?;
15    p.expect_prompt()?;
16    p.send_line("sleep 0.5")?;
17    p.expect_prompt()?;
18    // bash writes 'ping 8.8.8.8' to stdout again to state which job was put into foreground
19    p.send_line("fg")?;
20    p.expect("ping 8.8.8.8")?;
21    p.send(ControlCode::try_from("^D").unwrap())?;
22    p.expect("packet loss")?;
23
24    Ok(())
25}
examples/ftp_interact.rs (line 37)
11fn main() -> Result<(), Error> {
12    let mut auth = false;
13    let mut login_lookup = Lookup::new();
14    let opts = InteractOptions::new(&mut auth).on_output(|ctx| {
15        if login_lookup
16            .on(ctx.buf, ctx.eof, "Login successful")?
17            .is_some()
18        {
19            **ctx.state = true;
20            return Ok(true);
21        }
22
23        Ok(false)
24    });
25
26    let mut p = spawn("ftp bks4-speedtest-1.tele2.net")?;
27
28    let mut stdin = Stdin::open()?;
29    p.interact(&mut stdin, stdout()).spawn(opts)?;
30    stdin.close()?;
31
32    if !auth {
33        println!("An authefication was not passed");
34        return Ok(());
35    }
36
37    p.expect("ftp>")?;
38    p.send_line("cd upload")?;
39    p.expect("successfully changed.")?;
40    p.send_line("pwd")?;
41    p.expect(Regex("[0-9]+ \"/upload\""))?;
42    p.send(ControlCode::EndOfTransmission)?;
43    p.expect("Goodbye.")?;
44    Ok(())
45}
Source

pub fn check<N>(&mut self, needle: N) -> Result<Captures, Error>
where N: Needle,

Check verifies if a pattern is matched. Returns empty found structure if nothing found.

Is a non blocking version of Session::expect. But its strategy of matching is different from it. It makes search against all bytes available.

§Example
use expectrl::{spawn, Regex};
use std::time::Duration;

let mut p = spawn("echo 123").unwrap();
let m = p.check(Regex("\\d+")).unwrap();
assert_eq!(m.get(0).unwrap(), b"123");
Source

pub fn is_matched<N>(&mut self, needle: N) -> Result<bool, Error>
where N: Needle,

The functions checks if a pattern is matched. It doesn’t consumes bytes from stream.

Its strategy of matching is different from the one in Session::expect. It makes search agains all bytes available.

If you want to get a matched result Session::check and Session::expect is a better option. Because it is not guaranteed that Session::check or Session::expect with the same parameters: - will successed even right after Session::is_matched call. - will operate on the same bytes.

IMPORTANT:

If you call this method with crate::Eof pattern be aware that eof indication MAY be lost on the next interactions. It depends from a process you spawn. So it might be better to use Session::check or Session::expect with Eof.

§Example
use expectrl::{spawn, Regex};
use std::time::Duration;

let mut p = spawn("cat").unwrap();
p.send_line("123");
let m = p.is_matched(Regex("\\d+")).unwrap();
assert_eq!(m, true);
Source§

impl<Proc, Stream: Write> Session<Proc, Stream>

Source

pub fn send<B: AsRef<[u8]>>(&mut self, buf: B) -> Result<()>

Send text to child’s STDIN.

You can also use methods from std::io::Write instead.

§Example
use expectrl::{spawn, ControlCode};

let mut proc = spawn("cat").unwrap();

proc.send("Hello");
proc.send(b"World");
proc.send(ControlCode::try_from("^C").unwrap());
Examples found in repository?
examples/ftp.rs (line 15)
4fn main() -> Result<(), Error> {
5    let mut p = spawn("ftp bks4-speedtest-1.tele2.net")?;
6    p.expect(Regex("Name \\(.*\\):"))?;
7    p.send_line("anonymous")?;
8    p.expect("Password")?;
9    p.send_line("test")?;
10    p.expect("ftp>")?;
11    p.send_line("cd upload")?;
12    p.expect("successfully changed.")?;
13    p.send_line("pwd")?;
14    p.expect(Regex("[0-9]+ \"/upload\""))?;
15    p.send(ControlCode::EndOfTransmission)?;
16    p.expect("Goodbye.")?;
17    Ok(())
18}
More examples
Hide additional examples
examples/ping.rs (line 10)
6fn main() -> Result<(), Error> {
7    let mut p = spawn_bash()?;
8    p.send_line("ping 8.8.8.8")?;
9    p.expect("bytes of data")?;
10    p.send(ControlCode::try_from("^Z").unwrap())?;
11    p.expect_prompt()?;
12    // bash writes 'ping 8.8.8.8' to stdout again to state which job was put into background
13    p.send_line("bg")?;
14    p.expect("ping 8.8.8.8")?;
15    p.expect_prompt()?;
16    p.send_line("sleep 0.5")?;
17    p.expect_prompt()?;
18    // bash writes 'ping 8.8.8.8' to stdout again to state which job was put into foreground
19    p.send_line("fg")?;
20    p.expect("ping 8.8.8.8")?;
21    p.send(ControlCode::try_from("^D").unwrap())?;
22    p.expect("packet loss")?;
23
24    Ok(())
25}
examples/ftp_interact.rs (line 42)
11fn main() -> Result<(), Error> {
12    let mut auth = false;
13    let mut login_lookup = Lookup::new();
14    let opts = InteractOptions::new(&mut auth).on_output(|ctx| {
15        if login_lookup
16            .on(ctx.buf, ctx.eof, "Login successful")?
17            .is_some()
18        {
19            **ctx.state = true;
20            return Ok(true);
21        }
22
23        Ok(false)
24    });
25
26    let mut p = spawn("ftp bks4-speedtest-1.tele2.net")?;
27
28    let mut stdin = Stdin::open()?;
29    p.interact(&mut stdin, stdout()).spawn(opts)?;
30    stdin.close()?;
31
32    if !auth {
33        println!("An authefication was not passed");
34        return Ok(());
35    }
36
37    p.expect("ftp>")?;
38    p.send_line("cd upload")?;
39    p.expect("successfully changed.")?;
40    p.send_line("pwd")?;
41    p.expect(Regex("[0-9]+ \"/upload\""))?;
42    p.send(ControlCode::EndOfTransmission)?;
43    p.expect("Goodbye.")?;
44    Ok(())
45}
examples/bash.rs (line 37)
8fn main() {
9    let mut p = spawn_bash().unwrap();
10
11    // case 1: execute
12    let hostname = p.execute("hostname").unwrap();
13    println!("Current hostname: {:?}", String::from_utf8_lossy(&hostname));
14
15    // case 2: wait until done, only extract a few infos
16    p.send_line("wc /etc/passwd").unwrap();
17    // `exp_regex` returns both string-before-match and match itself, discard first
18    let lines = p.expect(Regex("[0-9]+")).unwrap();
19    let words = p.expect(Regex("[0-9]+")).unwrap();
20    let bytes = p.expect(Regex("[0-9]+")).unwrap();
21    p.expect_prompt().unwrap(); // go sure `wc` is really done
22    println!(
23        "/etc/passwd has {} lines, {} words, {} chars",
24        String::from_utf8_lossy(&lines[0]),
25        String::from_utf8_lossy(&words[0]),
26        String::from_utf8_lossy(&bytes[0]),
27    );
28
29    // case 3: read while program is still executing
30    p.send_line("ping 8.8.8.8").unwrap(); // returns when it sees "bytes of data" in output
31    for _ in 0..5 {
32        // times out if one ping takes longer than 2s
33        let duration = p.expect(Regex("[0-9. ]+ ms")).unwrap();
34        println!("Roundtrip time: {}", String::from_utf8_lossy(&duration[0]));
35    }
36
37    p.send(ControlCode::EOT).unwrap();
38}
Source

pub fn send_line<B: AsRef<[u8]>>(&mut self, buf: B) -> Result<()>

Send a line to child’s STDIN.

§Example
use expectrl::{spawn, ControlCode};

let mut proc = spawn("cat").unwrap();

proc.send_line("Hello");
proc.send_line(b"World");
proc.send_line(ControlCode::try_from("^C").unwrap());
Examples found in repository?
examples/log.rs (line 9)
3fn main() -> Result<(), Error> {
4    let p = spawn("cat")?;
5    let mut p = expectrl::session::log(p, std::io::stdout())?;
6
7    #[cfg(not(feature = "async"))]
8    {
9        p.send_line("Hello World")?;
10        p.expect("Hello World")?;
11    }
12    #[cfg(feature = "async")]
13    {
14        futures_lite::future::block_on(async {
15            p.send_line("Hello World").await?;
16            p.expect("Hello World").await
17        })?;
18    }
19
20    Ok(())
21}
More examples
Hide additional examples
examples/ftp.rs (line 7)
4fn main() -> Result<(), Error> {
5    let mut p = spawn("ftp bks4-speedtest-1.tele2.net")?;
6    p.expect(Regex("Name \\(.*\\):"))?;
7    p.send_line("anonymous")?;
8    p.expect("Password")?;
9    p.send_line("test")?;
10    p.expect("ftp>")?;
11    p.send_line("cd upload")?;
12    p.expect("successfully changed.")?;
13    p.send_line("pwd")?;
14    p.expect(Regex("[0-9]+ \"/upload\""))?;
15    p.send(ControlCode::EndOfTransmission)?;
16    p.expect("Goodbye.")?;
17    Ok(())
18}
examples/check.rs (line 12)
4fn main() {
5    let mut session = spawn("python ./tests/source/ansi.py").expect("Can't spawn a session");
6
7    loop {
8        match check!(
9            &mut session,
10            _ = "Password: " => {
11                println!("Set password to SECURE_PASSWORD");
12                session.send_line("SECURE_PASSWORD").unwrap();
13            },
14            _ = "Continue [y/n]:" => {
15                println!("Stop processing");
16                session.send_line("n").unwrap();
17            },
18        ) {
19            Err(Error::Eof) => break,
20            result => result.unwrap(),
21        };
22    }
23}
examples/ftp_interact.rs (line 38)
11fn main() -> Result<(), Error> {
12    let mut auth = false;
13    let mut login_lookup = Lookup::new();
14    let opts = InteractOptions::new(&mut auth).on_output(|ctx| {
15        if login_lookup
16            .on(ctx.buf, ctx.eof, "Login successful")?
17            .is_some()
18        {
19            **ctx.state = true;
20            return Ok(true);
21        }
22
23        Ok(false)
24    });
25
26    let mut p = spawn("ftp bks4-speedtest-1.tele2.net")?;
27
28    let mut stdin = Stdin::open()?;
29    p.interact(&mut stdin, stdout()).spawn(opts)?;
30    stdin.close()?;
31
32    if !auth {
33        println!("An authefication was not passed");
34        return Ok(());
35    }
36
37    p.expect("ftp>")?;
38    p.send_line("cd upload")?;
39    p.expect("successfully changed.")?;
40    p.send_line("pwd")?;
41    p.expect(Regex("[0-9]+ \"/upload\""))?;
42    p.send(ControlCode::EndOfTransmission)?;
43    p.expect("Goodbye.")?;
44    Ok(())
45}
Source§

impl<P, S: Read + NonBlocking> Session<P, S>

Source

pub fn try_read(&mut self, buf: &mut [u8]) -> Result<usize>

Try to read in a non-blocking mode.

Returns [std::io::ErrorKind::WouldBlock] in case if there’s nothing to read.

Source

pub fn is_empty(&mut self) -> Result<bool>

Verifyes if stream is empty or not.

Source§

impl Session

Source

pub fn spawn(command: Command) -> Result<Self, Error>

Spawns a session on a platform process.

§Example
use std::process::Command;
use expectrl::Session;

let p = Session::spawn(Command::new("cat"));
Source§

impl<P, S> Session<P, S>

Source

pub fn interact<I, O>( &mut self, input: I, output: O, ) -> InteractSession<&mut Self, I, O>

Interact gives control of the child process to the interactive user (the human at the keyboard or a Reader implementator).

You can set different callbacks to the session, see InteractSession.

Keystrokes are sent to the child process, and the stdout and stderr output of the child process is printed.

When the user types the escape_character this method will return control to a running process. The escape_character will not be transmitted. The default for escape_character is entered as Ctrl-], the very same as BSD telnet.

This simply echos the child stdout and stderr to the real stdout and it echos the real stdin to the child stdin.

BEWARE that interact finishes after a process stops. So after the return you may not obtain a correct status of a process.

In not async mode the default version uses a buzy loop.

  • On linux you can use a polling version using the corresponding feature.
  • On windows the feature is also present but it spawns a thread for pooling which creates a set of obsticales. Specifically if you’re planning to call interact() multiple times it may not be safe. Because the previous threads may still be running.

It works via polling in async mode on both unix and windows.

§Example
use std::io::{stdout, Cursor};
use expectrl::{self, interact::InteractOptions};

let mut p = expectrl::spawn("cat").unwrap();

let input = Cursor::new(String::from("Some text right here"));

p.interact(input, stdout()).spawn(InteractOptions::default()).unwrap();
Examples found in repository?
examples/interact.rs (line 22)
14fn main() {
15    let mut sh = spawn(SHELL).expect("Error while spawning sh");
16
17    println!("Now you're in interacting mode");
18    println!("To return control back to main type CTRL-] combination");
19
20    let mut stdin = Stdin::open().expect("Failed to create stdin");
21
22    sh.interact(&mut stdin, stdout())
23        .spawn(&mut InteractOptions::default())
24        .expect("Failed to start interact");
25
26    stdin.close().expect("Failed to close a stdin");
27
28    println!("Exiting");
29}
More examples
Hide additional examples
examples/ftp_interact.rs (line 29)
11fn main() -> Result<(), Error> {
12    let mut auth = false;
13    let mut login_lookup = Lookup::new();
14    let opts = InteractOptions::new(&mut auth).on_output(|ctx| {
15        if login_lookup
16            .on(ctx.buf, ctx.eof, "Login successful")?
17            .is_some()
18        {
19            **ctx.state = true;
20            return Ok(true);
21        }
22
23        Ok(false)
24    });
25
26    let mut p = spawn("ftp bks4-speedtest-1.tele2.net")?;
27
28    let mut stdin = Stdin::open()?;
29    p.interact(&mut stdin, stdout()).spawn(opts)?;
30    stdin.close()?;
31
32    if !auth {
33        println!("An authefication was not passed");
34        return Ok(());
35    }
36
37    p.expect("ftp>")?;
38    p.send_line("cd upload")?;
39    p.expect("successfully changed.")?;
40    p.send_line("pwd")?;
41    p.expect(Regex("[0-9]+ \"/upload\""))?;
42    p.send(ControlCode::EndOfTransmission)?;
43    p.expect("Goodbye.")?;
44    Ok(())
45}
examples/interact_with_callback.rs (line 60)
17fn main() {
18    let mut output_action = Lookup::new();
19    let mut input_action = Lookup::new();
20    let mut state = State::default();
21    let opts = InteractOptions::new(&mut state)
22        .on_output(|mut ctx| {
23            let m = output_action.on(ctx.buf, ctx.eof, "Continue [y/n]:")?;
24            if m.is_some() {
25                ctx.state.wait_for_continue = Some(true);
26            };
27
28            let m = output_action.on(ctx.buf, ctx.eof, Regex("status:\\s*.*\\w+.*\\r\\n"))?;
29            if m.is_some() {
30                ctx.state.stutus_verification_counter =
31                    Some(ctx.state.stutus_verification_counter.map_or(1, |c| c + 1));
32                output_action.clear();
33            }
34
35            Ok(false)
36        })
37        .on_input(|mut ctx| {
38            let m = input_action.on(ctx.buf, ctx.eof, "y")?;
39            if m.is_some() {
40                if let Some(_a @ true) = ctx.state.wait_for_continue {
41                    ctx.state.pressed_yes_on_continue = Some(true);
42                }
43            };
44
45            let m = input_action.on(ctx.buf, ctx.eof, "n")?;
46            if m.is_some() {
47                if let Some(_a @ true) = ctx.state.wait_for_continue {
48                    ctx.state.pressed_yes_on_continue = Some(false);
49                }
50            }
51
52            Ok(false)
53        });
54
55    let mut session = spawn("python ./tests/source/ansi.py").expect("Can't spawn a session");
56
57    let mut stdin = Stdin::open().unwrap();
58    let stdout = std::io::stdout();
59
60    let mut interact = session.interact(&mut stdin, stdout);
61
62    let is_alive = interact.spawn(opts).expect("Failed to start interact");
63
64    if !is_alive {
65        println!("The process was exited");
66        #[cfg(unix)]
67        println!("Status={:?}", interact.get_status());
68    }
69
70    stdin.close().unwrap();
71
72    println!("RESULTS");
73    println!(
74        "Number of time 'Y' was pressed = {}",
75        state.pressed_yes_on_continue.unwrap_or_default()
76    );
77    println!(
78        "Status counter = {}",
79        state.stutus_verification_counter.unwrap_or_default()
80    );
81}

Trait Implementations§

Source§

impl<P, S: Read> BufRead for Session<P, S>

Source§

fn fill_buf(&mut self) -> Result<&[u8]>

Returns the contents of the internal buffer, filling it with more data, via Read methods, if empty. Read more
Source§

fn consume(&mut self, amt: usize)

Marks the given amount of additional bytes from the internal buffer as having been read. Subsequent calls to read only return bytes that have not been marked as read. Read more
Source§

fn has_data_left(&mut self) -> Result<bool, Error>

🔬This is a nightly-only experimental API. (buf_read_has_data_left)
Checks if there is any data left to be read. Read more
1.0.0 · Source§

fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes into buf until the delimiter byte or EOF is reached. Read more
1.83.0 · Source§

fn skip_until(&mut self, byte: u8) -> Result<usize, Error>

Skips all bytes until the delimiter byte or EOF is reached. Read more
1.0.0 · Source§

fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until a newline (the 0xA byte) is reached, and append them to the provided String buffer. Read more
1.0.0 · Source§

fn split(self, byte: u8) -> Split<Self>
where Self: Sized,

Returns an iterator over the contents of this reader split on the byte byte. Read more
1.0.0 · Source§

fn lines(self) -> Lines<Self>
where Self: Sized,

Returns an iterator over the lines of this reader. Read more
Source§

impl<P: Debug, S: Debug> Debug for Session<P, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P, S: Read> Read for Session<P, S>

Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

impl<P, S: Write> Write for Session<P, S>

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

§

impl<P, S> Freeze for Session<P, S>
where P: Freeze, S: Freeze,

§

impl<P, S> RefUnwindSafe for Session<P, S>

§

impl<P, S> Send for Session<P, S>
where P: Send, S: Send,

§

impl<P, S> Sync for Session<P, S>
where P: Sync, S: Sync,

§

impl<P, S> Unpin for Session<P, S>
where P: Unpin, S: Unpin,

§

impl<P, S> UnwindSafe for Session<P, S>
where P: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.