Struct EngineConnection

Source
pub struct EngineConnection {
    pub process: Child,
    pub stdout: BufReader<ChildStdout>,
    pub stdin: ChildStdin,
}

Fields§

§process: Child§stdout: BufReader<ChildStdout>§stdin: ChildStdin

Implementations§

Source§

impl EngineConnection

Source

pub fn from_process(process: Child) -> Result<Self, UciCreationError>

§Errors

UciCreationError::Spawn is guaranteed not to occur here.

Source

pub fn from_path(path: &str) -> Result<Self, UciCreationError>

Creates a new connection from the given executable path.

§Errors
  • Spawning the process errored.
  • Stdout is None.
  • Stdin is None.
Source

pub async fn send_message(&mut self, message: &GuiMessage) -> Result<()>

Sends a message.

§Errors

See AsyncWriteExt::write_all.

Source

pub async fn skip_lines(&mut self, count: usize) -> Result<()>

Skips some lines.

§Errors

See AsyncBufReadExt::read_line.

Source

pub async fn read_message( &mut self, ) -> Result<EngineMessage, UciReadMessageError>

Reads a line and attempts to parse it into a message.

§Errors
  • Reading resulted in an IO error.
  • Parsing the message errors.
Source§

impl EngineConnection

Source

pub async fn use_uci(&mut self) -> Result<(Option<Id>, Vec<OptionMessage>)>

Sends the GuiMessage::UseUci message and returns the engine’s ID and a vector of options once the uciok message is received.

§Errors

See AsyncWriteExt::write_all.

Source

pub async fn go(&mut self, message: Go) -> Result<(Vec<Box<Info>>, BestMove)>

Sends the go message to the engine and waits for the bestmove message response, returning it, along with a list of info messages.

Note that the engine will only send the bestmove message if you set some constraint to prevent the engine from thinking forever. This can be depth or wtime/btime.

If you don’t have that kind of constraint but want to receive scores and best continuations (without waiting until the engine finishes with bestmove), use the Self::go_async_info function.

§Errors
  • Writing (sending the message) errored.
  • Reading (reading back the responses) errored.
Source

pub async fn go_only_last_info( &mut self, message: Go, ) -> Result<(Option<Info>, BestMove)>

Equivalent to the Self::go function, but doesn’t store a vector of info messages, and returns only the last one instead.

Source

pub fn go_async_info( arc_self: Arc<Mutex<Self>>, message: Go, ) -> (Receiver<Box<Info>>, JoinHandle<Result<BestMove>>)

Same as Self::go, but instead of returning the info messages and the best move together (after waiting for the engine), it immediately returns a tuple which contains:

  • A receiver for the info messages.
  • A handle to a task which will send info messages to the receiver and, once the engine returns a bestmove message, will return that message.

The spawned task will never panic. It is thus safe to call Result::unwrap on the handle. However, the value returned by the handle may be an error, so don’t call unwrap twice!

Source

pub async fn is_ready(&mut self) -> Result<()>

Sends the isready message and waits for the readyok response.

§Errors
  • Writing (sending the message) errored.
  • Reading (reading until readyok) errored.

Trait Implementations§

Source§

impl Debug for EngineConnection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.