Skip to content

Commit

Permalink
chore: make quit and isready inbuilt commands
Browse files Browse the repository at this point in the history
  • Loading branch information
raklaptudirm committed Apr 18, 2024
1 parent 11f4a1f commit 799ff67
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
8 changes: 7 additions & 1 deletion uai/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use std::collections::HashMap;
use std::io::{self, BufRead};
use std::sync::{Arc, Mutex};

use crate::inbuilt;

use super::{Command, FlagValues, RunError, RunErrorType};

/// Client represents an UAI engine client. It can accept and parse commands
Expand Down Expand Up @@ -133,9 +135,13 @@ impl<T: Send, E: RunError> Client<T, E> {
/// .command("perft", perft_cmd);
/// ```
#[allow(clippy::new_without_default)]
#[rustfmt::skip]
pub fn new() -> Self {
Client::<T, E> {
commands: HashMap::new(),
commands: HashMap::from([
("quit".into(), inbuilt::quit()),
("isready".into(), inbuilt::isready()),
]),
}
}

Expand Down
8 changes: 4 additions & 4 deletions uai/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub trait RunError: Send + From<RunErrorType> + Into<RunErrorType> {}
#[macro_export]
macro_rules! quit {
() => {
Err(ataxx_uai::RunErrorType::Quit.into())
Err(RunErrorType::Quit.into())
};
}

Expand All @@ -140,7 +140,7 @@ macro_rules! quit {
macro_rules! error {
($($arg:tt)*) => {
{
Err(ataxx_uai::RunErrorType::Error(format!($($arg)*)).into())
Err(RunErrorType::Error(format!($($arg)*)).into())
}
};
}
Expand All @@ -154,7 +154,7 @@ macro_rules! error {
macro_rules! error_val {
($($arg:tt)*) => {
{
ataxx_uai::RunErrorType::Error(format!($($arg)*)).into()
RunErrorType::Error(format!($($arg)*)).into()
}
};
}
Expand All @@ -166,7 +166,7 @@ macro_rules! error_val {
#[macro_export]
macro_rules! fatal {
($($arg:tt)*) => {
Err(ataxx_uai::RunErrorType::Fatal(format!($($arg)*)).into())
Err(RunErrorType::Fatal(format!($($arg)*)).into())
};
}

Expand Down
12 changes: 12 additions & 0 deletions uai/src/inbuilt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::{quit, Command, RunError, RunErrorType};

pub fn quit<T: Send, E: RunError>() -> Command<T, E> {
Command::new(|_ctx, _flag| quit!())
}

pub fn isready<T: Send, E: RunError>() -> Command<T, E> {
Command::new(|_ctx, _flag| {
println!("readyok");
Ok(())
})
}
2 changes: 2 additions & 0 deletions uai/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod inbuilt;

mod client;
mod cmd;
mod flag;
Expand Down

0 comments on commit 799ff67

Please sign in to comment.