arcis-interface 0.11.1

Defines the data interface and core types for Arcis circuits.
Documentation
mod json;
pub mod path_with_hash;
mod string;
mod types;

use crate::path_with_hash::PathWithHash;
pub use json::ManticoreInterface;
use std::env;
pub use types::{CircuitInterface, ScalarKind, Value};

pub fn write_interface(
    interface: String,
    circuit_name: &str,
    out_dir: &Option<String>,
) -> Result<[PathWithHash; 2], std::io::Error> {
    use crate::string::snake_case_to_camel_case;

    const DEFAULT_CIRCUIT_OUT_DIR: &str = "build";

    let current_dir = env::current_dir()?;

    let circuits_dir = current_dir.join(out_dir.as_deref().unwrap_or(DEFAULT_CIRCUIT_OUT_DIR));
    let file_path = circuits_dir.join(format!("{circuit_name}.idarc"));
    let ts_file_path = circuits_dir.join(format!("{circuit_name}.ts"));

    std::fs::create_dir_all(&circuits_dir)?;

    let interface_bytes = interface.into_bytes();
    let idarc_file = PathWithHash::new(
        &interface_bytes,
        file_path
            .into_os_string()
            .into_string()
            .expect("current directory contains non-UTF-8 characters"),
    )?;

    // Write the TypeScript interface with the circuit name in camel case (from snake case)
    let camel_case_name = snake_case_to_camel_case(circuit_name);
    let ts_bytes = [
        &format!("export type {} = ", camel_case_name).into_bytes()[..],
        &interface_bytes[..],
    ]
    .concat();
    let ts_file = PathWithHash::new(
        &ts_bytes,
        ts_file_path
            .into_os_string()
            .into_string()
            .expect("current directory contains non-UTF-8 characters"),
    )?;

    Ok([idarc_file, ts_file])
}