chess/formats/
chessbase.rs1use core::ffi::c_str::CStr;
8
9use encoding_rs::WINDOWS_1252;
10
11pub mod archive;
12pub mod database;
13pub mod game;
14pub mod huffman;
15pub mod index;
16pub mod player;
17pub mod table;
18pub mod tournament;
19
20fn cstr(input: &[u8]) -> String {
21 let value = CStr::from_bytes_until_nul(input).expect("valid string");
22 let (value, encoding, had_errors) = WINDOWS_1252.decode(value.to_bytes());
23 assert_eq!(encoding, WINDOWS_1252);
24 assert!(!had_errors);
25 value.to_string()
26}
27
28fn optional<T: Default + PartialEq>(value: T) -> Option<T> {
30 (value != T::default()).then_some(value)
31}