Engine

Struct Engine 

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

This represents the controller of an GTP Engine.

You establish a connection like this:

use std::time::Duration;
use gtp::Command;
use gtp::controller::Engine;

let mut ctrl = Engine::new("/usr/bin/gnugo", &["--mode", "gtp"]);
assert!(ctrl.start().is_ok());

ctrl.send(Command::cmd("name", |e| e));
let resp = ctrl.wait_response(Duration::from_millis(500)).unwrap();
let ev = resp.entities(|ep| ep.s().s()).unwrap();
assert_eq!(ev[0].to_string(), "GNU");
assert_eq!(ev[1].to_string(), "Go");
assert_eq!(resp.text(), "GNU Go");

Implementations§

Source§

impl Engine

Source

pub fn new(cmd: &str, args: &[&str]) -> Engine

Creates a new Engine instance with the path to the engine binary and the arguments to pass to the engine.

Source

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

Starts the engine in the background.

Source

pub fn send(&mut self, cmd: Command) -> u32

Sends a command to the engine. Returns the ID of the command.

Source

pub fn stderr(&self) -> String

Returns the currently captured stderr output of the engine.

Source

pub fn clear_stderr(&mut self)

Clears the up to now returned output of the engine.

Source

pub fn wait_response(&mut self, timeout: Duration) -> Result<Response, Error>

This method waits for a maximum amount of time for a response from the GTP engine.

If no response was received in the given time Error::PollAgain is returned.

Source

pub fn poll_response(&mut self) -> Result<Response, Error>

This method polls once for a response from the GTP engine.

If no response was found Error::PollAgain is returned.

Auto Trait Implementations§

§

impl Freeze for Engine

§

impl !RefUnwindSafe for Engine

§

impl Send for Engine

§

impl !Sync for Engine

§

impl Unpin for Engine

§

impl !UnwindSafe for Engine

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.