Skip to content

Commit

Permalink
Fix doctests and import issue in uci/uciderive
Browse files Browse the repository at this point in the history
  • Loading branch information
bsamseth committed Aug 21, 2024
1 parent 95b5487 commit 59cbd66
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 0 additions & 2 deletions engine/src/opts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::path::PathBuf;

use anyhow::{Context, Result};

use uci::UciOptions;

use crate::newtypes::{Depth, Value};
Expand Down
10 changes: 6 additions & 4 deletions uci/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ listen to a mpsc receiver and match over the commands.
This shows the outline of a main program loop for a UCI chess engine.
```
use uci::UciOptions;
#[derive(Debug, UciOptions)]
struct MyOptions {
#[uci(name = "Hash", kind = "Spin", default = "16", min = "1", max = "128")]
#[uci(name = "Hash", kind = "spin", default = "16", min = "1", max = "128")]
pub hash_size_mb: usize,
#[uci(name = "SyzygyPath", kind = "String")]
pub syzygy_path: Option<PathBuf>,
#[uci(name = "SyzygyPath", kind = "string")]
pub syzygy_path: Option<std::path::PathBuf>,
}
let interface = uci::Interface::default();
Expand All @@ -30,7 +32,7 @@ while let Ok(cmd) = interface.commands.recv() {
options.print_options();
println!("uciok");
}
uci::Command::SetOption(uci::Option { name, value }) => {
uci::Command::SetOption(uci::EngineOption { name, value }) => {
if let Err(e) = options.set_option(&name, &value) {
eprintln!("{e}");
continue;
Expand Down
7 changes: 4 additions & 3 deletions uci/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ pub use uciderive::UciOptions;
///
/// ```rust
/// use uci::UciOptions;
///
/// #[derive(Debug, UciOptions)]
/// struct MyOptions {
/// #[uci(name = "Hash", kind = "Spin", default = "16", min = "1", max = "128")]
/// #[uci(name = "Hash", kind = "spin", default = "16", min = "1", max = "128")]
/// pub hash_size_mb: usize,
/// #[uci(name = "SyzygyPath", kind = "String")]
/// pub syzygy_path: Option<PathBuf>,
/// #[uci(name = "SyzygyPath", kind = "string")]
/// pub syzygy_path: Option<std::path::PathBuf>,
/// }
/// ```
pub trait UciOptions: Default {
Expand Down
3 changes: 2 additions & 1 deletion uciderive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,14 @@ fn impl_set_option(fields: &Fields<UciOptionAttrubute>) -> proc_macro2::TokenStr
};
quote! {
#name => {
use ::anyhow::Context;
self.#ident = #assign;
}
}
});

quote! {
fn set_option(&mut self, name: &str, value: &str) -> Result<()> {
fn set_option(&mut self, name: &str, value: &str) -> ::anyhow::Result<()> {
match name.to_lowercase().as_str() {
#(#field_setter)*
_ => return Err(anyhow::anyhow!("unknown UCI option: {name}")),
Expand Down

0 comments on commit 59cbd66

Please sign in to comment.