Struct Connection

Source
pub struct Connection { /* private fields */ }
Expand description

A handle to a running command server instance.

Implementations§

Source§

impl Connection

Source

pub fn new() -> Result<Connection>

Spawns a new command server process.

Source

pub fn read_hello(&mut self) -> Result<(Vec<String>, String)>

Reads and parses the server hello message. Returns a tuple of ([capabilities], encoding).

§Errors

Returns an I/O error if reading or parsing the hello message failed.

Source

pub fn raw_command(&mut self, command: Vec<&[u8]>) -> Result<CommandRun<'_>>

Sends the given command to Mercurial, returning an iterator over the results.

Examples found in repository?
examples/client.rs (line 9)
5fn run_command(cmdserver: &mut CommandServer, command: Vec<&[u8]>) -> (i32, Vec<u8>, Vec<u8>) {
6    let (mut result, mut output, mut error) =
7        (-1i32, vec![], vec![]);
8    let run = cmdserver.connection
9        .raw_command(command)
10        .ok().expect("failed to send 'log' command");
11
12    for chunk in run {
13        match chunk {
14            Ok(Chunk::Output(s)) => output.extend(s),
15            Ok(Chunk::Error(s)) => error.extend(s),
16            Ok(Chunk::Result(r)) => { result = r },
17            Ok(_) => unimplemented!(),
18            Err(e) => panic!("failed to read command results: {}", e),
19        }
20    }
21
22    (result, output, error)
23}
Source

pub fn close(&mut self) -> Result<ExitStatus>

Shuts down the command server process.

Examples found in repository?
examples/client.rs (line 32)
25fn main() {
26    let mut cmdserver = CommandServer::new().ok().expect("failed to start command server");
27    println!("capabilities: {:?}", cmdserver.capabilities);
28    println!("encoding: {:?}", cmdserver.encoding);
29
30    let (result, output, error) =
31        run_command(&mut cmdserver, vec![b"log", b"-l", b"5"]);
32    cmdserver.connection.close().ok().expect("command server did not stop cleanly");
33
34    println!("output: {}",
35             String::from_utf8(output).unwrap().trim_right_matches('\n'));
36    println!("error: {}",
37             String::from_utf8(error).unwrap().trim_right_matches('\n'));
38    println!("result: {:?}", result);
39}

Auto Trait Implementations§

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.