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
impl Engine
Sourcepub fn new(cmd: &str, args: &[&str]) -> Engine
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.
Sourcepub fn send(&mut self, cmd: Command) -> u32
pub fn send(&mut self, cmd: Command) -> u32
Sends a command to the engine. Returns the ID of the command.
Sourcepub fn clear_stderr(&mut self)
pub fn clear_stderr(&mut self)
Clears the up to now returned output of the engine.
Sourcepub fn wait_response(&mut self, timeout: Duration) -> Result<Response, Error>
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.
Sourcepub fn poll_response(&mut self) -> Result<Response, Error>
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> 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