Skip to main content

cube_rust/
ffi.rs

1//! Raw FFI bindings to the underlying C++ Rubik's Cube solver library.
2
3use std::os::raw::{c_char, c_int};
4
5/// Default buffer byte size for C++ string outputs.
6pub const CUBE_BS: usize = 128;
7
8/// The 54-facelet string representation of a solved Rubik's Cube (U, R, F, D, L, B).
9pub const CUBE_ID: &str = "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB";
10
11/// Raw result codes returned by the C++ solver.
12#[repr(i32)]
13#[derive(Debug, Copy, Clone, PartialEq, Eq)]
14pub enum SolveResult {
15    Success = 0,
16    Unsolvable = 1,
17    NotFound = 2,
18    InvalidSrc = 3,
19    InvalidTgt = 4,
20    UnknownErr = 5,
21}
22
23extern "C" {
24    /// Converts a result code into a human-readable C-string description
25    pub fn solve_result_to_string(sr: SolveResult) -> *const c_char;
26
27    pub fn cube_init(
28        use_symmetry: bool,
29        table_dir: *const c_char
30    );
31
32    /// Core solve function
33    pub fn solve(
34        buf: *mut c_char,
35        src: *const c_char,
36        tgt: *const c_char,
37        step: c_int
38    ) -> SolveResult;
39
40    /// Checks if a given color cube represents a valid, solvable cube
41    pub fn solvable(color_cube: *const c_char) -> bool;
42
43    /// Applies a maneuver string to a color cube and writes the resulting state to the buffer
44    pub fn facecube(
45        buf: *mut c_char, 
46        maneuver: *const c_char,
47        cube: *const c_char
48    ) -> bool;
49
50    /// Converts a color cube OR a maneuver string into its string representation
51    pub fn permutation(
52        buf: *mut c_char, 
53        ms_or_cube: *const c_char, 
54        format: c_int
55    ) -> bool;
56}