ActionPath

Struct ActionPath 

Source
pub struct ActionPath { /* private fields */ }
Expand description

Detailed action representation with full path information for UI applications.

This stores the complete path of squares visited during a move, which is necessary to generate proper algebraic notation (especially for multi-capture sequences). Use this for UI display, move history, and game notation.

For high-speed simulations (perft, AI training), use Action instead.

§Notation Format (Section 10 of rules)

  • Non-capturing move: from-to (e.g., d3-d4)
  • Single capture: fromxto (e.g., d4xd6)
  • Multi-capture: fromxmidxto (e.g., d4xd6xf6)
  • Promotion: from-to=K (e.g., d7-d8=K)
  • Capture with promotion: fromxto=K (e.g., c7xc8=K)

Implementations§

Source§

impl ActionPath

Source

pub const fn new_move(src: Square, dest: Square, is_promotion: bool) -> Self

Creates a new non-capturing move.

Source

pub fn new_capture(src: Square, landings: &[Square], is_promotion: bool) -> Self

Creates a new capture with a path of landing squares.

§Arguments
  • src - The source square
  • landings - Slice of landing squares (where the piece lands after each capture)
  • is_promotion - Whether the piece is promoted at the end
Source

pub const fn source(&self) -> Square

Returns the source square.

Source

pub const fn destination(&self) -> Square

Returns the destination (final) square.

Source

pub const fn is_capture(&self) -> bool

Returns true if this is a capture action.

Source

pub const fn is_promotion(&self) -> bool

Returns true if this action results in promotion.

Source

pub const fn path_len(&self) -> usize

Returns the number of squares in the path.

Source

pub fn path(&self) -> &[Square]

Returns the path as a slice.

Source

pub fn to_notation(&self) -> String

Converts the action to its notation string.

§Performance

This method is optimized to avoid heap allocations where possible by writing directly to a fixed-size buffer. The maximum notation length is:

  • 2 chars per square × 17 squares = 34 chars
  • 16 separators (- or x) = 16 chars
  • “=K” suffix = 2 chars
  • Total: 52 chars max
Source

pub fn write_notation(&self, buf: &mut [u8]) -> usize

Writes the notation directly to a byte buffer without allocation.

This is a performance optimization for batch processing scenarios where you need to generate many notations without heap allocations. For most use cases, prefer to_notation instead.

Returns the number of bytes written.

§Panics

In debug builds, panics if the buffer is smaller than 52 bytes.

§Example
use kish::{ActionPath, Square};

let action = ActionPath::new_move(Square::E3, Square::E4, false);
let mut buf = [0u8; 52];
let len = action.write_notation(&mut buf);
let notation = std::str::from_utf8(&buf[..len]).unwrap();
assert_eq!(notation, "e3-e4");

Trait Implementations§

Source§

impl Clone for ActionPath

Source§

fn clone(&self) -> ActionPath

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ActionPath

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for ActionPath

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Hash for ActionPath

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ActionPath

Source§

fn eq(&self, other: &ActionPath) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ActionPath

Source§

impl Eq for ActionPath

Source§

impl StructuralPartialEq for ActionPath

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.