pub struct EngineConnection {
pub process: Child,
pub stdout: BufReader<ChildStdout>,
pub stdin: ChildStdin,
}Fields§
§process: Child§stdout: BufReader<ChildStdout>§stdin: ChildStdinImplementations§
Source§impl EngineConnection
impl EngineConnection
Sourcepub fn from_process(process: Child) -> Result<Self, UciCreationError>
pub fn from_process(process: Child) -> Result<Self, UciCreationError>
§Errors
UciCreationError::Spawn is guaranteed not to occur here.
Sourcepub fn from_path(path: &str) -> Result<Self, UciCreationError>
pub fn from_path(path: &str) -> Result<Self, UciCreationError>
Sourcepub async fn send_message(&mut self, message: &GuiMessage) -> Result<()>
pub async fn send_message(&mut self, message: &GuiMessage) -> Result<()>
Sourcepub async fn skip_lines(&mut self, count: usize) -> Result<()>
pub async fn skip_lines(&mut self, count: usize) -> Result<()>
Sourcepub async fn read_message(
&mut self,
) -> Result<EngineMessage, UciReadMessageError>
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
impl EngineConnection
Sourcepub async fn use_uci(&mut self) -> Result<(Option<Id>, Vec<OptionMessage>)>
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
Sourcepub async fn go(&mut self, message: Go) -> Result<(Vec<Box<Info>>, BestMove)>
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.
Sourcepub async fn go_only_last_info(
&mut self,
message: Go,
) -> Result<(Option<Info>, BestMove)>
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.
Sourcepub fn go_async_info(
arc_self: Arc<Mutex<Self>>,
message: Go,
) -> (Receiver<Box<Info>>, JoinHandle<Result<BestMove>>)
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
bestmovemessage, 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!