#[macro_use]
extern crate lazy_static;
pub mod scramble;
pub mod error;
pub mod constants;
pub mod coord;
pub mod cubie;
pub mod facelet;
pub mod symmetries;
pub mod moves;
pub mod pruning;
pub mod solver;
use std::{fs, path::Path};
use bincode::{
config::{self, Configuration},
decode_from_slice, encode_to_vec,
error::DecodeError,
Decode, Encode,
};
use crate::error::Error;
use crate::moves::Move;
const CONFIG: Configuration = config::standard();
fn write_table<P, T: Encode>(path: P, table: &T) -> Result<(), Error>
where
P: AsRef<Path>,
{
let encoded = encode_to_vec(table, CONFIG)?;
fs::write(path, encoded)?;
Ok(())
}
fn decode_table<T: Decode>(bytes: &[u8]) -> Result<T, Error> {
let (decoded, written) = decode_from_slice(bytes, CONFIG)?;
let additional = bytes.len() - written;
if additional != 0 {
return Err(DecodeError::UnexpectedEnd { additional })?;
}
Ok(decoded)
}