importCottonMacFFIimportFoundation/// The Rust core (`crates/cotton-mac-ffi`): three C functions, JSON in and/// out. Every call is synchronous and may block on the network or on a/// source's probe, so callers run it off the main thread (`AppModel.call`).enumCore {/// Open the one core over `config`. The answer is `{ ok, error?, code? }`.staticfuncopen(configJSON: String) -> Data { take(cotton_mac_open(configJSON)) }/// One method. `argsJSON` nil sends no arguments.staticfunc call(_ method: String, argsJSON: String?) -> Data {iflet argsJSON {return take(cotton_mac_call(method, argsJSON)) }return take(cotton_mac_call(method, nil)) }privatestaticfunc take(_ pointer: UnsafeMutablePointer<CChar>?) -> Data {guardlet pointer else { returnData(#"{"ok":false,"error":"the core answered nothing"}"#.utf8) }defer { cotton_mac_free(pointer) }returnData(String(cString: pointer).utf8) }}/// What every answer carries.structCoreAnswer: Decodable, Sendable {let ok: Boollet error: String?let code: String?}/// The configuration the core opens with (camelCase, `cotton_mac::app::Config`).structCoreConfig: Encodable, Sendable {let dataDir: Stringlet objectUrl: Stringlet deviceId: Stringlet machine: String/// The name the person gave this Mac, and the running version: its device row.let deviceName: Stringlet appVersion: Stringlet home: Stringlet helpersDir: String}/// The arguments of a call, encoded once on the caller's side.enumCoreArgs {staticfunc json(_ object: [String: Any]) -> String {guardlet data = try? JSONSerialization.data(withJSONObject: object),let text = String(data: data, encoding: .utf8)else { return"{}" }return text }}