/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/ */ import { type UniffiByteArray } from "./ffi-types.ts"; import { type UniffiReferenceHolder } from "./callbacks.ts"; import { type UniffiRustCallStatus } from "./rust-call.ts"; // This Result combines RustCallStatus and ReferenceHolder. // This is principally so we can _return_ something from calling from native into typescript. export type UniffiResult = UniffiReferenceHolder | UniffiRustCallStatus; export const UniffiResult = { ready(): UniffiResult { return { code: 0 }; }, writeError( result: UniffiResult, code: number, buf: UniffiByteArray, ): UniffiResult { const status = result as UniffiRustCallStatus; status.code = code; status.errorBuf = buf; return status; }, writeSuccess(result: UniffiResult, obj: T): UniffiResult { const refHolder = result as UniffiReferenceHolder; refHolder.pointee = obj; return refHolder; }, success(pointee: T): UniffiResult { return { pointee }; }, };