rubiks-cube-3x3-solver / src/notation.rs

raw file 600 bytes
//! Notation parsing and formatting for cube moves.

use crate::error::Result;
use crate::moves::Move;

/// Parse a whitespace-separated move string into a vector of moves.
pub fn parse_moves(s: &str) -> Result<Vec<Move>> {
    crate::scramble::scramble_from_str(s).map_err(Into::into)
}

/// Format a vector of moves into standard notation.
pub fn format_moves(moves: &[Move]) -> String {
    crate::scramble::scramble_to_str(&moves.to_vec()).unwrap_or_default()
}

/// Validate that a string is a well-formed move sequence.
pub fn validate(s: &str) -> Result<()> {
    parse_moves(s).map(|_| ())
}