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
impl ActionPath
Sourcepub const fn new_move(src: Square, dest: Square, is_promotion: bool) -> Self
pub const fn new_move(src: Square, dest: Square, is_promotion: bool) -> Self
Creates a new non-capturing move.
Sourcepub fn new_capture(src: Square, landings: &[Square], is_promotion: bool) -> Self
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 squarelandings- Slice of landing squares (where the piece lands after each capture)is_promotion- Whether the piece is promoted at the end
Sourcepub const fn destination(&self) -> Square
pub const fn destination(&self) -> Square
Returns the destination (final) square.
Sourcepub const fn is_capture(&self) -> bool
pub const fn is_capture(&self) -> bool
Returns true if this is a capture action.
Sourcepub const fn is_promotion(&self) -> bool
pub const fn is_promotion(&self) -> bool
Returns true if this action results in promotion.
Sourcepub fn to_notation(&self) -> String
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
Sourcepub fn write_notation(&self, buf: &mut [u8]) -> usize
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
impl Clone for ActionPath
Source§fn clone(&self) -> ActionPath
fn clone(&self) -> ActionPath
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ActionPath
impl Debug for ActionPath
Source§impl Display for ActionPath
impl Display for ActionPath
Source§impl Hash for ActionPath
impl Hash for ActionPath
Source§impl PartialEq for ActionPath
impl PartialEq for ActionPath
impl Copy for ActionPath
impl Eq for ActionPath
impl StructuralPartialEq for ActionPath
Auto Trait Implementations§
impl Freeze for ActionPath
impl RefUnwindSafe for ActionPath
impl Send for ActionPath
impl Sync for ActionPath
impl Unpin for ActionPath
impl UnwindSafe for ActionPath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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