pub struct Connection { /* private fields */ }
Expand description
A handle to a running command server instance.
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn new() -> Result<Connection>
pub fn new() -> Result<Connection>
Spawns a new command server process.
Sourcepub fn read_hello(&mut self) -> Result<(Vec<String>, String)>
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.
Sourcepub fn raw_command(&mut self, command: Vec<&[u8]>) -> Result<CommandRun<'_>>
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}
Sourcepub fn close(&mut self) -> Result<ExitStatus>
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§
impl Freeze for Connection
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnwindSafe for Connection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more