car-ffi-common 0.6.0

Shared logic for FFI bindings (NAPI, PyO3) — JSON wrappers for verify, multi-agent, scheduler
Documentation
//! JSON wrapper around `car-accounts`.
//!
//! Error codes: `backend`.

use serde_json::{json, Value};

fn err_json(e: car_accounts::AccountError) -> String {
    json!({"code": "backend", "message": e.to_string()}).to_string()
}

pub fn list() -> Result<Value, String> {
    let r = car_accounts::list().map_err(err_json)?;
    serde_json::to_value(&r)
        .map_err(|e| json!({"code": "backend", "message": e.to_string()}).to_string())
}

pub fn open_settings(account_id: Option<&str>) -> Result<Value, String> {
    car_accounts::open_settings(account_id).map_err(err_json)?;
    Ok(json!({"opened": true}))
}