Skip to main content

rsshogi_csa/
lib.rs

1//! Engine-agnostic CSA server protocol surface.
2//!
3//! This crate turns one line of the CSA server protocol into a typed
4//! [`CsaCommand`] and back. It has no dependencies, no I/O, and no board
5//! representation: sockets, clocks, and legality belong to the layer above.
6//!
7//! ```
8//! use rsshogi_csa::{format_command, parse_line, CsaCommand, EndMarker};
9//!
10//! let command = parse_line("+7776FU,T12")?;
11//! assert_eq!(format_command(&command), "+7776FU,T12");
12//!
13//! let CsaCommand::Move(line) = command else { unreachable!() };
14//! assert_eq!(line.csa.as_str(), "+7776FU");
15//! assert_eq!(line.elapsed, Some(12));
16//!
17//! assert_eq!(parse_line("#RESIGN")?, CsaCommand::End(EndMarker::Resign));
18//! # Ok::<(), rsshogi_csa::ParseError>(())
19//! ```
20//!
21//! The `BEGIN Game_Summary` proposal spans many lines and is assembled by
22//! [`GameSummaryReader`] instead, which keeps the `BEGIN Position` body verbatim.
23//!
24//! # Scope
25//!
26//! CSA has two things that share a name. The *record format* — `.csa` files with
27//! a `V2.2` header and `$EVENT` metadata — is handled by the `records` feature of
28//! the [`rsshogi`](https://crates.io/crates/rsshogi) crate. The *server protocol*
29//! — `LOGIN`, `BEGIN Game_Summary`, `+7776FU,T12`, `#WIN` — is what this crate
30//! handles.
31
32#![forbid(unsafe_code)]
33#![deny(missing_docs)]
34
35mod error;
36mod format;
37mod model;
38mod parser;
39mod summary;
40
41pub use error::{ParseError, ParseErrorKind, ParseErrorSite};
42pub use format::format_command;
43pub use model::{
44    Color, CsaCommand, CsaCommandDirection, CsaMove, EndMarker, EndMarkerKind, GameSummary,
45    InfoLine, MetaCommand, MoveLine, SpecialMove, TimeConfig, TimeScale, TimeUnit, TurnPreference,
46};
47pub use parser::{parse_line, parse_line_strict};
48pub use summary::GameSummaryReader;