rust/chg/src/clientext.rs
author Georges Racinet <gracinet@anybox.fr>
Thu, 27 Sep 2018 16:51:36 +0200
changeset 40272 a36c5e23c055
parent 39979 045ea159418d
child 43836 ce088b38f92b
permissions -rw-r--r--
rust: iterator bindings to C code In this changeset, still made of Rust code only, we expose the Rust iterator for instantiation and consumption from C code. The idea is that both the index and index_get_parents() will be passed from the C extension, hence avoiding a hard link dependency to parsers.so, so that the crate can still be built and tested independently. On the other hand, parsers.so will use the symbols defined in this changeset.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39978
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     1
// Copyright 2018 Yuya Nishihara <yuya@tcha.org>
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     2
//
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     3
// This software may be used and distributed according to the terms of the
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     4
// GNU General Public License version 2 or any later version.
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     5
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     6
//! cHg extensions to command server client.
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     7
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     8
use std::ffi::OsStr;
39979
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
     9
use std::os::unix::ffi::OsStrExt;
39978
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    10
use std::os::unix::io::AsRawFd;
39979
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    11
use std::path::Path;
39978
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    12
use tokio_hglib::{Client, Connection};
39979
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    13
use tokio_hglib::protocol::OneShotRequest;
39978
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    14
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    15
use super::attachio::AttachIo;
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    16
use super::message;
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    17
use super::runcommand::ChgRunCommand;
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    18
use super::uihandler::SystemHandler;
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    19
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    20
pub trait ChgClientExt<C>
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    21
    where C: Connection + AsRawFd,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    22
{
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    23
    /// Attaches the client file descriptors to the server.
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    24
    fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E>
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    25
        where I: AsRawFd,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    26
              O: AsRawFd,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    27
              E: AsRawFd;
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    28
39979
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    29
    /// Changes the working directory of the server.
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    30
    fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    31
        where P: AsRef<Path>;
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    32
39978
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    33
    /// Runs the specified Mercurial command with cHg extension.
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    34
    fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    35
        where I: IntoIterator<Item = P>,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    36
              P: AsRef<OsStr>,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    37
              H: SystemHandler;
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    38
}
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    39
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    40
impl<C> ChgClientExt<C> for Client<C>
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    41
    where C: Connection + AsRawFd,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    42
{
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    43
    fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E>
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    44
        where I: AsRawFd,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    45
              O: AsRawFd,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    46
              E: AsRawFd,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    47
    {
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    48
        AttachIo::with_client(self, stdin, stdout, Some(stderr))
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    49
    }
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    50
39979
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    51
    fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    52
        where P: AsRef<Path>,
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    53
    {
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    54
        OneShotRequest::start_with_args(self, b"chdir", dir.as_ref().as_os_str().as_bytes())
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    55
    }
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39978
diff changeset
    56
39978
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    57
    fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    58
        where I: IntoIterator<Item = P>,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    59
              P: AsRef<OsStr>,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    60
              H: SystemHandler,
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    61
    {
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    62
        ChgRunCommand::with_client(self, handler, message::pack_args_os(args))
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    63
    }
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    64
}