From bbc1b8a9a0b489e25455719a2ffe665498f5dfd8 Mon Sep 17 00:00:00 2001 From: EthanShoeDev <13422990+EthanShoeDev@users.noreply.github.com> Date: Sat, 13 Sep 2025 02:52:24 -0400 Subject: [PATCH] one error down --- apps/mobile/tsconfig.json | 3 +- docs/todos.md | 4 + packages/react-native-uniffi-russh/.gitignore | 3 +- .../react-native-uniffi-russh/package.json | 2 +- .../src/NativeUniffiRussh.ts | 10 - .../src/__tests__/index.test.tsx | 1 - .../src/generated/foobar-ffi.ts | 306 ---- .../src/generated/foobar.ts | 1237 ----------------- .../react-native-uniffi-russh/src/index.tsx | 40 - .../react-native-uniffi-russh/tsconfig.json | 3 +- 10 files changed, 9 insertions(+), 1600 deletions(-) delete mode 100644 packages/react-native-uniffi-russh/src/NativeUniffiRussh.ts delete mode 100644 packages/react-native-uniffi-russh/src/__tests__/index.test.tsx delete mode 100644 packages/react-native-uniffi-russh/src/generated/foobar-ffi.ts delete mode 100644 packages/react-native-uniffi-russh/src/generated/foobar.ts delete mode 100644 packages/react-native-uniffi-russh/src/index.tsx diff --git a/apps/mobile/tsconfig.json b/apps/mobile/tsconfig.json index 6025e32..0221e1b 100644 --- a/apps/mobile/tsconfig.json +++ b/apps/mobile/tsconfig.json @@ -28,6 +28,5 @@ ".expo/types/**/*.ts", "expo-env.d.ts", "eslint.config.js" - ], - "exclude": ["**/node_modules"] + ] } diff --git a/docs/todos.md b/docs/todos.md index 795cf19..3d417db 100644 --- a/docs/todos.md +++ b/docs/todos.md @@ -35,3 +35,7 @@ - https://docs.expo.dev/versions/latest/sdk/gl-view/ - https://code.visualstudio.com/docs/terminal/shell-integration - https://github.com/termux/termux-app/wiki/Termux-Libraries/bd010af15b8434ba136c32fa70a50c504ea04363 + +Uniffi is broken on RN 0.80 + +- https://github.com/realm/realm-js/issues/7011#issuecomment-3149613234 diff --git a/packages/react-native-uniffi-russh/.gitignore b/packages/react-native-uniffi-russh/.gitignore index e8421eb..246423b 100644 --- a/packages/react-native-uniffi-russh/.gitignore +++ b/packages/react-native-uniffi-russh/.gitignore @@ -89,4 +89,5 @@ nitrogen/ rust_modules/ *.a android/ -cpp/ \ No newline at end of file +cpp/ +src/ \ No newline at end of file diff --git a/packages/react-native-uniffi-russh/package.json b/packages/react-native-uniffi-russh/package.json index addd45f..2c1ef83 100644 --- a/packages/react-native-uniffi-russh/package.json +++ b/packages/react-native-uniffi-russh/package.json @@ -39,7 +39,7 @@ "typecheck": "tsc", "lint": "eslint \"**/*.{js,ts,tsx}\"", "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib", - "prepare": "bob build", + "prepare": "pnpm run ubrn:checkout && pnpm run ubrn:android && bob build", "release": "release-it --only-version" }, "keywords": [ diff --git a/packages/react-native-uniffi-russh/src/NativeUniffiRussh.ts b/packages/react-native-uniffi-russh/src/NativeUniffiRussh.ts deleted file mode 100644 index ae5bffc..0000000 --- a/packages/react-native-uniffi-russh/src/NativeUniffiRussh.ts +++ /dev/null @@ -1,10 +0,0 @@ -// Generated by uniffi-bindgen-react-native -import type { TurboModule } from 'react-native'; -import { TurboModuleRegistry } from 'react-native'; - -export interface Spec extends TurboModule { - installRustCrate(): boolean; - cleanupRustCrate(): boolean; -} - -export default TurboModuleRegistry.getEnforcing('UniffiRussh'); diff --git a/packages/react-native-uniffi-russh/src/__tests__/index.test.tsx b/packages/react-native-uniffi-russh/src/__tests__/index.test.tsx deleted file mode 100644 index bf84291..0000000 --- a/packages/react-native-uniffi-russh/src/__tests__/index.test.tsx +++ /dev/null @@ -1 +0,0 @@ -it.todo('write a test'); diff --git a/packages/react-native-uniffi-russh/src/generated/foobar-ffi.ts b/packages/react-native-uniffi-russh/src/generated/foobar-ffi.ts deleted file mode 100644 index dbd0548..0000000 --- a/packages/react-native-uniffi-russh/src/generated/foobar-ffi.ts +++ /dev/null @@ -1,306 +0,0 @@ -// This file was autogenerated by some hot garbage in the `uniffi-bindgen-react-native` crate. -// Trust me, you don't want to mess with it! - -import { - type StructuralEquality as UniffiStructuralEquality, - type UniffiForeignFuture as RuntimeUniffiForeignFuture, - type UniffiRustCallStatus, - type UniffiRustArcPtr, - type UniffiRustFutureContinuationCallback as RuntimeUniffiRustFutureContinuationCallback, - type UniffiResult, -} from 'uniffi-bindgen-react-native'; - -interface NativeModuleInterface { - ubrn_uniffi_internal_fn_func_ffi__string_to_byte_length( - string: string, - uniffi_out_err: UniffiRustCallStatus - ): number; - ubrn_uniffi_internal_fn_func_ffi__string_to_arraybuffer( - string: string, - uniffi_out_err: UniffiRustCallStatus - ): Uint8Array; - ubrn_uniffi_internal_fn_func_ffi__arraybuffer_to_string( - buffer: Uint8Array, - uniffi_out_err: UniffiRustCallStatus - ): string; - ubrn_uniffi_foobar_fn_clone_binaryoperator( - ptr: bigint, - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_free_binaryoperator( - ptr: bigint, - uniffi_out_err: UniffiRustCallStatus - ): void; - ubrn_uniffi_foobar_fn_init_callback_vtable_binaryoperator( - vtable: UniffiVTableCallbackInterfaceBinaryOperator - ): void; - ubrn_uniffi_foobar_fn_method_binaryoperator_perform( - ptr: bigint, - lhs: bigint, - rhs: bigint, - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_clone_calculator( - ptr: bigint, - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_free_calculator( - ptr: bigint, - uniffi_out_err: UniffiRustCallStatus - ): void; - ubrn_uniffi_foobar_fn_constructor_calculator_new( - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_method_calculator_calculate( - ptr: bigint, - op: bigint, - lhs: bigint, - rhs: bigint, - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_method_calculator_calculate_more( - ptr: bigint, - op: bigint, - rhs: bigint, - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_method_calculator_last_result( - ptr: bigint, - uniffi_out_err: UniffiRustCallStatus - ): Uint8Array; - ubrn_uniffi_foobar_fn_clone_safeaddition( - ptr: bigint, - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_free_safeaddition( - ptr: bigint, - uniffi_out_err: UniffiRustCallStatus - ): void; - ubrn_uniffi_foobar_fn_constructor_safeaddition_new( - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_method_safeaddition_perform( - ptr: bigint, - lhs: bigint, - rhs: bigint, - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_clone_safedivision( - ptr: bigint, - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_free_safedivision( - ptr: bigint, - uniffi_out_err: UniffiRustCallStatus - ): void; - ubrn_uniffi_foobar_fn_constructor_safedivision_new( - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_method_safedivision_perform( - ptr: bigint, - lhs: bigint, - rhs: bigint, - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_func_safe_addition_operator( - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_fn_func_safe_division_operator( - uniffi_out_err: UniffiRustCallStatus - ): bigint; - ubrn_uniffi_foobar_checksum_func_safe_addition_operator(): number; - ubrn_uniffi_foobar_checksum_func_safe_division_operator(): number; - ubrn_uniffi_foobar_checksum_method_binaryoperator_perform(): number; - ubrn_uniffi_foobar_checksum_method_calculator_calculate(): number; - ubrn_uniffi_foobar_checksum_method_calculator_calculate_more(): number; - ubrn_uniffi_foobar_checksum_method_calculator_last_result(): number; - ubrn_uniffi_foobar_checksum_method_safeaddition_perform(): number; - ubrn_uniffi_foobar_checksum_method_safedivision_perform(): number; - ubrn_uniffi_foobar_checksum_constructor_calculator_new(): number; - ubrn_uniffi_foobar_checksum_constructor_safeaddition_new(): number; - ubrn_uniffi_foobar_checksum_constructor_safedivision_new(): number; - ubrn_ffi_foobar_uniffi_contract_version(): number; - ubrn_uniffi_internal_fn_method_binaryoperator_ffi__bless_pointer( - pointer: bigint, - uniffi_out_err: UniffiRustCallStatus - ): UniffiRustArcPtr; - ubrn_uniffi_internal_fn_method_calculator_ffi__bless_pointer( - pointer: bigint, - uniffi_out_err: UniffiRustCallStatus - ): UniffiRustArcPtr; - ubrn_uniffi_internal_fn_method_safeaddition_ffi__bless_pointer( - pointer: bigint, - uniffi_out_err: UniffiRustCallStatus - ): UniffiRustArcPtr; - ubrn_uniffi_internal_fn_method_safedivision_ffi__bless_pointer( - pointer: bigint, - uniffi_out_err: UniffiRustCallStatus - ): UniffiRustArcPtr; -} - -// Casting globalThis to any allows us to look for `NativeFoobar` -// if it was added via JSI. -// -// We use a getter here rather than simply `globalThis.NativeFoobar` so that -// if/when the startup sequence isn't just so, an empty value isn't inadvertantly cached. -const getter: () => NativeModuleInterface = () => - (globalThis as any).NativeFoobar; -export default getter; - -// Structs and function types for calling back into Typescript from Rust. -export type UniffiRustFutureContinuationCallback = ( - data: bigint, - pollResult: number -) => void; -type UniffiForeignFutureFree = (handle: bigint) => void; -type UniffiCallbackInterfaceFree = (handle: bigint) => void; -export type UniffiForeignFuture = { - handle: bigint; - free: UniffiForeignFutureFree; -}; -export type UniffiForeignFutureStructU8 = { - returnValue: number; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteU8 = ( - callbackData: bigint, - result: UniffiForeignFutureStructU8 -) => void; -export type UniffiForeignFutureStructI8 = { - returnValue: number; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteI8 = ( - callbackData: bigint, - result: UniffiForeignFutureStructI8 -) => void; -export type UniffiForeignFutureStructU16 = { - returnValue: number; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteU16 = ( - callbackData: bigint, - result: UniffiForeignFutureStructU16 -) => void; -export type UniffiForeignFutureStructI16 = { - returnValue: number; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteI16 = ( - callbackData: bigint, - result: UniffiForeignFutureStructI16 -) => void; -export type UniffiForeignFutureStructU32 = { - returnValue: number; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteU32 = ( - callbackData: bigint, - result: UniffiForeignFutureStructU32 -) => void; -export type UniffiForeignFutureStructI32 = { - returnValue: number; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteI32 = ( - callbackData: bigint, - result: UniffiForeignFutureStructI32 -) => void; -export type UniffiForeignFutureStructU64 = { - returnValue: bigint; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteU64 = ( - callbackData: bigint, - result: UniffiForeignFutureStructU64 -) => void; -export type UniffiForeignFutureStructI64 = { - returnValue: bigint; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteI64 = ( - callbackData: bigint, - result: UniffiForeignFutureStructI64 -) => void; -export type UniffiForeignFutureStructF32 = { - returnValue: number; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteF32 = ( - callbackData: bigint, - result: UniffiForeignFutureStructF32 -) => void; -export type UniffiForeignFutureStructF64 = { - returnValue: number; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteF64 = ( - callbackData: bigint, - result: UniffiForeignFutureStructF64 -) => void; -export type UniffiForeignFutureStructPointer = { - returnValue: bigint; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompletePointer = ( - callbackData: bigint, - result: UniffiForeignFutureStructPointer -) => void; -export type UniffiForeignFutureStructRustBuffer = { - returnValue: Uint8Array; - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteRustBuffer = ( - callbackData: bigint, - result: UniffiForeignFutureStructRustBuffer -) => void; -export type UniffiForeignFutureStructVoid = { - callStatus: UniffiRustCallStatus; -}; -export type UniffiForeignFutureCompleteVoid = ( - callbackData: bigint, - result: UniffiForeignFutureStructVoid -) => void; -type UniffiCallbackInterfaceBinaryOperatorMethod0 = ( - uniffiHandle: bigint, - lhs: bigint, - rhs: bigint -) => UniffiResult; -export type UniffiVTableCallbackInterfaceBinaryOperator = { - perform: UniffiCallbackInterfaceBinaryOperatorMethod0; - uniffiFree: UniffiCallbackInterfaceFree; -}; - -// UniffiRustFutureContinuationCallback is generated as part of the component interface's -// ffi_definitions. However, we need it in the runtime. -// We could: -// (a) do some complicated template logic to ensure the declaration is not generated here (possible) -// (b) import the generated declaration into the runtime (m a y b e) or… -// (c) generate the declaration anyway, and use a different declaration in the runtime. -// -// We chose (c) here as the simplest. In addition, we perform a compile time check that -// the two versions of `UniffiRustFutureContinuationCallback` are structurally equivalent. -// -// If you see the error: -// ``` -// Type 'true' is not assignable to type 'false'.(2322) -// ``` -// Then a new version of uniffi has changed the signature of the callback. Most likely, code in -// `typescript/src/async-rust-call.ts` will need to be changed. -// -// If you see the error: -// ``` -// Cannot find name 'UniffiRustFutureContinuationCallback'. Did you mean 'RuntimeUniffiRustFutureContinuationCallback'?(2552) -// ``` -// then you may not be using callbacks or promises, and uniffi is now not generating Futures and callbacks. -// You should not generate this if that is the case. -// -// ('You' being the bindings generator maintainer). -const isRustFutureContinuationCallbackTypeCompatible: UniffiStructuralEquality< - RuntimeUniffiRustFutureContinuationCallback, - UniffiRustFutureContinuationCallback -> = true; -const isUniffiForeignFutureTypeCompatible: UniffiStructuralEquality< - RuntimeUniffiForeignFuture, - UniffiForeignFuture -> = true; diff --git a/packages/react-native-uniffi-russh/src/generated/foobar.ts b/packages/react-native-uniffi-russh/src/generated/foobar.ts deleted file mode 100644 index 88311fc..0000000 --- a/packages/react-native-uniffi-russh/src/generated/foobar.ts +++ /dev/null @@ -1,1237 +0,0 @@ -// This file was autogenerated by some hot garbage in the `uniffi-bindgen-react-native` crate. -// Trust me, you don't want to mess with it! -import nativeModule, { - type UniffiVTableCallbackInterfaceBinaryOperator, -} from './foobar-ffi'; -import { - type UniffiByteArray, - type UniffiHandle, - type UniffiObjectFactory, - type UniffiRustArcPtr, - type UnsafeMutableRawPointer, - AbstractFfiConverterByteArray, - FfiConverterInt32, - FfiConverterInt64, - FfiConverterObject, - FfiConverterObjectWithCallbacks, - FfiConverterOptional, - RustBuffer, - UniffiAbstractObject, - UniffiEnum, - UniffiError, - UniffiInternalError, - UniffiResult, - UniffiRustCaller, - destructorGuardSymbol, - pointerLiteralSymbol, - uniffiCreateFfiConverterString, - uniffiCreateRecord, - uniffiTraitInterfaceCallWithError, - uniffiTypeNameSymbol, -} from 'uniffi-bindgen-react-native'; - -// Get converters from the other files, if any. -const uniffiCaller = new UniffiRustCaller(() => ({ code: 0 })); - -const uniffiIsDebug = - // @ts-ignore -- The process global might not be defined - typeof process !== 'object' || - // @ts-ignore -- The process global might not be defined - process?.env?.NODE_ENV !== 'production' || - false; -// Public interface members begin here. - -export function safeAdditionOperator(): BinaryOperator { - return FfiConverterTypeBinaryOperator.lift( - uniffiCaller.rustCall( - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_func_safe_addition_operator( - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ) - ); -} -export function safeDivisionOperator(): BinaryOperator { - return FfiConverterTypeBinaryOperator.lift( - uniffiCaller.rustCall( - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_func_safe_division_operator( - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ) - ); -} - -export type ComputationResult = { - value: /*i64*/ bigint; -}; - -/** - * Generated factory for {@link ComputationResult} record objects. - */ -export const ComputationResult = (() => { - const defaults = () => ({}); - const create = (() => { - return uniffiCreateRecord>( - defaults - ); - })(); - return Object.freeze({ - /** - * Create a frozen instance of {@link ComputationResult}, with defaults specified - * in Rust, in the {@link foobar} crate. - */ - create, - - /** - * Create a frozen instance of {@link ComputationResult}, with defaults specified - * in Rust, in the {@link foobar} crate. - */ - new: create, - - /** - * Defaults specified in the {@link foobar} crate. - */ - defaults: () => Object.freeze(defaults()) as Partial, - }); -})(); - -const FfiConverterTypeComputationResult = (() => { - type TypeName = ComputationResult; - class FFIConverter extends AbstractFfiConverterByteArray { - read(from: RustBuffer): TypeName { - return { - value: FfiConverterInt64.read(from), - }; - } - write(value: TypeName, into: RustBuffer): void { - FfiConverterInt64.write(value.value, into); - } - allocationSize(value: TypeName): number { - return FfiConverterInt64.allocationSize(value.value); - } - } - return new FFIConverter(); -})(); - -const stringConverter = { - stringToBytes: (s: string) => - uniffiCaller.rustCall((status) => - nativeModule().ubrn_uniffi_internal_fn_func_ffi__string_to_arraybuffer( - s, - status - ) - ), - bytesToString: (ab: UniffiByteArray) => - uniffiCaller.rustCall((status) => - nativeModule().ubrn_uniffi_internal_fn_func_ffi__arraybuffer_to_string( - ab, - status - ) - ), - stringByteLength: (s: string) => - uniffiCaller.rustCall((status) => - nativeModule().ubrn_uniffi_internal_fn_func_ffi__string_to_byte_length( - s, - status - ) - ), -}; -const FfiConverterString = uniffiCreateFfiConverterString(stringConverter); - -// Error type: ComputationError - -// Enum: ComputationError -export enum ComputationError_Tags { - DivisionByZero = 'DivisionByZero', - Overflow = 'Overflow', - IllegalComputationWithInitState = 'IllegalComputationWithInitState', -} -export const ComputationError = (() => { - type DivisionByZero__interface = { - tag: ComputationError_Tags.DivisionByZero; - }; - - class DivisionByZero_ - extends UniffiError - implements DivisionByZero__interface - { - /** - * @private - * This field is private and should not be used, use `tag` instead. - */ - readonly [uniffiTypeNameSymbol] = 'ComputationError'; - readonly tag = ComputationError_Tags.DivisionByZero; - constructor() { - super('ComputationError', 'DivisionByZero'); - } - - static new(): DivisionByZero_ { - return new DivisionByZero_(); - } - - static instanceOf(obj: any): obj is DivisionByZero_ { - return obj.tag === ComputationError_Tags.DivisionByZero; - } - - static hasInner(obj: any): obj is DivisionByZero_ { - return false; - } - } - - type Overflow__interface = { - tag: ComputationError_Tags.Overflow; - }; - - class Overflow_ extends UniffiError implements Overflow__interface { - /** - * @private - * This field is private and should not be used, use `tag` instead. - */ - readonly [uniffiTypeNameSymbol] = 'ComputationError'; - readonly tag = ComputationError_Tags.Overflow; - constructor() { - super('ComputationError', 'Overflow'); - } - - static new(): Overflow_ { - return new Overflow_(); - } - - static instanceOf(obj: any): obj is Overflow_ { - return obj.tag === ComputationError_Tags.Overflow; - } - - static hasInner(obj: any): obj is Overflow_ { - return false; - } - } - - type IllegalComputationWithInitState__interface = { - tag: ComputationError_Tags.IllegalComputationWithInitState; - }; - - class IllegalComputationWithInitState_ - extends UniffiError - implements IllegalComputationWithInitState__interface - { - /** - * @private - * This field is private and should not be used, use `tag` instead. - */ - readonly [uniffiTypeNameSymbol] = 'ComputationError'; - readonly tag = ComputationError_Tags.IllegalComputationWithInitState; - constructor() { - super('ComputationError', 'IllegalComputationWithInitState'); - } - - static new(): IllegalComputationWithInitState_ { - return new IllegalComputationWithInitState_(); - } - - static instanceOf(obj: any): obj is IllegalComputationWithInitState_ { - return obj.tag === ComputationError_Tags.IllegalComputationWithInitState; - } - - static hasInner(obj: any): obj is IllegalComputationWithInitState_ { - return false; - } - } - - function instanceOf(obj: any): obj is ComputationError { - return obj[uniffiTypeNameSymbol] === 'ComputationError'; - } - - return Object.freeze({ - instanceOf, - DivisionByZero: DivisionByZero_, - Overflow: Overflow_, - IllegalComputationWithInitState: IllegalComputationWithInitState_, - }); -})(); - -export type ComputationError = InstanceType< - (typeof ComputationError)[keyof Omit] ->; - -// FfiConverter for enum ComputationError -const FfiConverterTypeComputationError = (() => { - const ordinalConverter = FfiConverterInt32; - type TypeName = ComputationError; - class FFIConverter extends AbstractFfiConverterByteArray { - read(from: RustBuffer): TypeName { - switch (ordinalConverter.read(from)) { - case 1: - return new ComputationError.DivisionByZero(); - case 2: - return new ComputationError.Overflow(); - case 3: - return new ComputationError.IllegalComputationWithInitState(); - default: - throw new UniffiInternalError.UnexpectedEnumCase(); - } - } - write(value: TypeName, into: RustBuffer): void { - switch (value.tag) { - case ComputationError_Tags.DivisionByZero: { - ordinalConverter.write(1, into); - return; - } - case ComputationError_Tags.Overflow: { - ordinalConverter.write(2, into); - return; - } - case ComputationError_Tags.IllegalComputationWithInitState: { - ordinalConverter.write(3, into); - return; - } - default: - // Throwing from here means that ComputationError_Tags hasn't matched an ordinal. - throw new UniffiInternalError.UnexpectedEnumCase(); - } - } - allocationSize(value: TypeName): number { - switch (value.tag) { - case ComputationError_Tags.DivisionByZero: { - return ordinalConverter.allocationSize(1); - } - case ComputationError_Tags.Overflow: { - return ordinalConverter.allocationSize(2); - } - case ComputationError_Tags.IllegalComputationWithInitState: { - return ordinalConverter.allocationSize(3); - } - default: - throw new UniffiInternalError.UnexpectedEnumCase(); - } - } - } - return new FFIConverter(); -})(); - -// Enum: ComputationState -export enum ComputationState_Tags { - Init = 'Init', - Computed = 'Computed', -} -export const ComputationState = (() => { - type Init__interface = { - tag: ComputationState_Tags.Init; - }; - - /** - * Initial state with no value computed - */ - class Init_ extends UniffiEnum implements Init__interface { - /** - * @private - * This field is private and should not be used, use `tag` instead. - */ - readonly [uniffiTypeNameSymbol] = 'ComputationState'; - readonly tag = ComputationState_Tags.Init; - constructor() { - super('ComputationState', 'Init'); - } - - static new(): Init_ { - return new Init_(); - } - - static instanceOf(obj: any): obj is Init_ { - return obj.tag === ComputationState_Tags.Init; - } - } - - type Computed__interface = { - tag: ComputationState_Tags.Computed; - inner: Readonly<{ result: ComputationResult }>; - }; - - class Computed_ extends UniffiEnum implements Computed__interface { - /** - * @private - * This field is private and should not be used, use `tag` instead. - */ - readonly [uniffiTypeNameSymbol] = 'ComputationState'; - readonly tag = ComputationState_Tags.Computed; - readonly inner: Readonly<{ result: ComputationResult }>; - constructor(inner: { result: ComputationResult }) { - super('ComputationState', 'Computed'); - this.inner = Object.freeze(inner); - } - - static new(inner: { result: ComputationResult }): Computed_ { - return new Computed_(inner); - } - - static instanceOf(obj: any): obj is Computed_ { - return obj.tag === ComputationState_Tags.Computed; - } - } - - function instanceOf(obj: any): obj is ComputationState { - return obj[uniffiTypeNameSymbol] === 'ComputationState'; - } - - return Object.freeze({ - instanceOf, - Init: Init_, - Computed: Computed_, - }); -})(); - -export type ComputationState = InstanceType< - (typeof ComputationState)[keyof Omit] ->; - -// FfiConverter for enum ComputationState -const FfiConverterTypeComputationState = (() => { - const ordinalConverter = FfiConverterInt32; - type TypeName = ComputationState; - class FFIConverter extends AbstractFfiConverterByteArray { - read(from: RustBuffer): TypeName { - switch (ordinalConverter.read(from)) { - case 1: - return new ComputationState.Init(); - case 2: - return new ComputationState.Computed({ - result: FfiConverterTypeComputationResult.read(from), - }); - default: - throw new UniffiInternalError.UnexpectedEnumCase(); - } - } - write(value: TypeName, into: RustBuffer): void { - switch (value.tag) { - case ComputationState_Tags.Init: { - ordinalConverter.write(1, into); - return; - } - case ComputationState_Tags.Computed: { - ordinalConverter.write(2, into); - const inner = value.inner; - FfiConverterTypeComputationResult.write(inner.result, into); - return; - } - default: - // Throwing from here means that ComputationState_Tags hasn't matched an ordinal. - throw new UniffiInternalError.UnexpectedEnumCase(); - } - } - allocationSize(value: TypeName): number { - switch (value.tag) { - case ComputationState_Tags.Init: { - return ordinalConverter.allocationSize(1); - } - case ComputationState_Tags.Computed: { - const inner = value.inner; - let size = ordinalConverter.allocationSize(2); - size += FfiConverterTypeComputationResult.allocationSize( - inner.result - ); - return size; - } - default: - throw new UniffiInternalError.UnexpectedEnumCase(); - } - } - } - return new FFIConverter(); -})(); - -/** - * A binary operator that performs some mathematical operation with two numbers. - */ -export interface BinaryOperator { - perform(lhs: /*i64*/ bigint, rhs: /*i64*/ bigint) /*throws*/ : /*i64*/ bigint; -} - -/** - * A binary operator that performs some mathematical operation with two numbers. - */ -export class BinaryOperatorImpl - extends UniffiAbstractObject - implements BinaryOperator -{ - readonly [uniffiTypeNameSymbol] = 'BinaryOperatorImpl'; - readonly [destructorGuardSymbol]: UniffiRustArcPtr; - readonly [pointerLiteralSymbol]: UnsafeMutableRawPointer; - // No primary constructor declared for this class. - private constructor(pointer: UnsafeMutableRawPointer) { - super(); - this[pointerLiteralSymbol] = pointer; - this[destructorGuardSymbol] = - uniffiTypeBinaryOperatorImplObjectFactory.bless(pointer); - } - - public perform( - lhs: /*i64*/ bigint, - rhs: /*i64*/ bigint - ): /*i64*/ bigint /*throws*/ { - return FfiConverterInt64.lift( - uniffiCaller.rustCallWithError( - /*liftError:*/ FfiConverterTypeComputationError.lift.bind( - FfiConverterTypeComputationError - ), - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_method_binaryoperator_perform( - uniffiTypeBinaryOperatorImplObjectFactory.clonePointer(this), - FfiConverterInt64.lower(lhs), - FfiConverterInt64.lower(rhs), - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ) - ); - } - - /** - * {@inheritDoc uniffi-bindgen-react-native#UniffiAbstractObject.uniffiDestroy} - */ - uniffiDestroy(): void { - const ptr = (this as any)[destructorGuardSymbol]; - if (ptr !== undefined) { - const pointer = uniffiTypeBinaryOperatorImplObjectFactory.pointer(this); - uniffiTypeBinaryOperatorImplObjectFactory.freePointer(pointer); - uniffiTypeBinaryOperatorImplObjectFactory.unbless(ptr); - delete (this as any)[destructorGuardSymbol]; - } - } - - static instanceOf(obj: any): obj is BinaryOperatorImpl { - return uniffiTypeBinaryOperatorImplObjectFactory.isConcreteType(obj); - } -} - -const uniffiTypeBinaryOperatorImplObjectFactory: UniffiObjectFactory = - (() => { - return { - create(pointer: UnsafeMutableRawPointer): BinaryOperator { - const instance = Object.create(BinaryOperatorImpl.prototype); - instance[pointerLiteralSymbol] = pointer; - instance[destructorGuardSymbol] = this.bless(pointer); - instance[uniffiTypeNameSymbol] = 'BinaryOperatorImpl'; - return instance; - }, - - bless(p: UnsafeMutableRawPointer): UniffiRustArcPtr { - return uniffiCaller.rustCall( - /*caller:*/ (status) => - nativeModule().ubrn_uniffi_internal_fn_method_binaryoperator_ffi__bless_pointer( - p, - status - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - unbless(ptr: UniffiRustArcPtr) { - ptr.markDestroyed(); - }, - - pointer(obj: BinaryOperator): UnsafeMutableRawPointer { - if ((obj as any)[destructorGuardSymbol] === undefined) { - throw new UniffiInternalError.UnexpectedNullPointer(); - } - return (obj as any)[pointerLiteralSymbol]; - }, - - clonePointer(obj: BinaryOperator): UnsafeMutableRawPointer { - const pointer = this.pointer(obj); - return uniffiCaller.rustCall( - /*caller:*/ (callStatus) => - nativeModule().ubrn_uniffi_foobar_fn_clone_binaryoperator( - pointer, - callStatus - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - freePointer(pointer: UnsafeMutableRawPointer): void { - uniffiCaller.rustCall( - /*caller:*/ (callStatus) => - nativeModule().ubrn_uniffi_foobar_fn_free_binaryoperator( - pointer, - callStatus - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - isConcreteType(obj: any): obj is BinaryOperator { - return ( - obj[destructorGuardSymbol] && - obj[uniffiTypeNameSymbol] === 'BinaryOperatorImpl' - ); - }, - }; - })(); -// FfiConverter for BinaryOperator -const FfiConverterTypeBinaryOperator = new FfiConverterObjectWithCallbacks( - uniffiTypeBinaryOperatorImplObjectFactory -); - -// Add a vtavble for the callbacks that go in BinaryOperator. - -// Put the implementation in a struct so we don't pollute the top-level namespace -const uniffiCallbackInterfaceBinaryOperator: { - vtable: UniffiVTableCallbackInterfaceBinaryOperator; - register: () => void; -} = { - // Create the VTable using a series of closures. - // ts automatically converts these into C callback functions. - vtable: { - perform: (uniffiHandle: bigint, lhs: bigint, rhs: bigint) => { - const uniffiMakeCall = (): /*i64*/ bigint => { - const jsCallback = FfiConverterTypeBinaryOperator.lift(uniffiHandle); - return jsCallback.perform( - FfiConverterInt64.lift(lhs), - FfiConverterInt64.lift(rhs) - ); - }; - const uniffiResult = UniffiResult.ready(); - const uniffiHandleSuccess = (obj: any) => { - UniffiResult.writeSuccess(uniffiResult, FfiConverterInt64.lower(obj)); - }; - const uniffiHandleError = (code: number, errBuf: UniffiByteArray) => { - UniffiResult.writeError(uniffiResult, code, errBuf); - }; - uniffiTraitInterfaceCallWithError( - /*makeCall:*/ uniffiMakeCall, - /*handleSuccess:*/ uniffiHandleSuccess, - /*handleError:*/ uniffiHandleError, - /*isErrorType:*/ ComputationError.instanceOf, - /*lowerError:*/ FfiConverterTypeComputationError.lower.bind( - FfiConverterTypeComputationError - ), - /*lowerString:*/ FfiConverterString.lower - ); - return uniffiResult; - }, - uniffiFree: (uniffiHandle: UniffiHandle): void => { - // BinaryOperator: this will throw a stale handle error if the handle isn't found. - FfiConverterTypeBinaryOperator.drop(uniffiHandle); - }, - }, - register: () => { - nativeModule().ubrn_uniffi_foobar_fn_init_callback_vtable_binaryoperator( - uniffiCallbackInterfaceBinaryOperator.vtable - ); - }, -}; - -/** - * A somewhat silly demonstration of functional core/imperative shell in the form of a calculator with arbitrary operators. - * - * Operations return a new calculator with updated internal state reflecting the computation. - */ -export interface CalculatorInterface { - /** - * Performs a calculation using the supplied binary operator and operands. - */ - calculate( - op: BinaryOperator, - lhs: /*i64*/ bigint, - rhs: /*i64*/ bigint - ) /*throws*/ : CalculatorInterface; - /** - * Performs a calculation using the supplied binary operator, the last computation result, and the supplied operand. - * - * The supplied operand will be the right-hand side in the mathematical operation. - */ - calculateMore( - op: BinaryOperator, - rhs: /*i64*/ bigint - ) /*throws*/ : CalculatorInterface; - lastResult(): ComputationResult | undefined; -} - -/** - * A somewhat silly demonstration of functional core/imperative shell in the form of a calculator with arbitrary operators. - * - * Operations return a new calculator with updated internal state reflecting the computation. - */ -export class Calculator - extends UniffiAbstractObject - implements CalculatorInterface -{ - readonly [uniffiTypeNameSymbol] = 'Calculator'; - readonly [destructorGuardSymbol]: UniffiRustArcPtr; - readonly [pointerLiteralSymbol]: UnsafeMutableRawPointer; - constructor() { - super(); - const pointer = uniffiCaller.rustCall( - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_constructor_calculator_new( - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ); - this[pointerLiteralSymbol] = pointer; - this[destructorGuardSymbol] = - uniffiTypeCalculatorObjectFactory.bless(pointer); - } - - /** - * Performs a calculation using the supplied binary operator and operands. - */ - public calculate( - op: BinaryOperator, - lhs: /*i64*/ bigint, - rhs: /*i64*/ bigint - ): CalculatorInterface /*throws*/ { - return FfiConverterTypeCalculator.lift( - uniffiCaller.rustCallWithError( - /*liftError:*/ FfiConverterTypeComputationError.lift.bind( - FfiConverterTypeComputationError - ), - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_method_calculator_calculate( - uniffiTypeCalculatorObjectFactory.clonePointer(this), - FfiConverterTypeBinaryOperator.lower(op), - FfiConverterInt64.lower(lhs), - FfiConverterInt64.lower(rhs), - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ) - ); - } - - /** - * Performs a calculation using the supplied binary operator, the last computation result, and the supplied operand. - * - * The supplied operand will be the right-hand side in the mathematical operation. - */ - public calculateMore( - op: BinaryOperator, - rhs: /*i64*/ bigint - ): CalculatorInterface /*throws*/ { - return FfiConverterTypeCalculator.lift( - uniffiCaller.rustCallWithError( - /*liftError:*/ FfiConverterTypeComputationError.lift.bind( - FfiConverterTypeComputationError - ), - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_method_calculator_calculate_more( - uniffiTypeCalculatorObjectFactory.clonePointer(this), - FfiConverterTypeBinaryOperator.lower(op), - FfiConverterInt64.lower(rhs), - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ) - ); - } - - public lastResult(): ComputationResult | undefined { - return FfiConverterOptionalTypeComputationResult.lift( - uniffiCaller.rustCall( - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_method_calculator_last_result( - uniffiTypeCalculatorObjectFactory.clonePointer(this), - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ) - ); - } - - /** - * {@inheritDoc uniffi-bindgen-react-native#UniffiAbstractObject.uniffiDestroy} - */ - uniffiDestroy(): void { - const ptr = (this as any)[destructorGuardSymbol]; - if (ptr !== undefined) { - const pointer = uniffiTypeCalculatorObjectFactory.pointer(this); - uniffiTypeCalculatorObjectFactory.freePointer(pointer); - uniffiTypeCalculatorObjectFactory.unbless(ptr); - delete (this as any)[destructorGuardSymbol]; - } - } - - static instanceOf(obj: any): obj is Calculator { - return uniffiTypeCalculatorObjectFactory.isConcreteType(obj); - } -} - -const uniffiTypeCalculatorObjectFactory: UniffiObjectFactory = - (() => { - return { - create(pointer: UnsafeMutableRawPointer): CalculatorInterface { - const instance = Object.create(Calculator.prototype); - instance[pointerLiteralSymbol] = pointer; - instance[destructorGuardSymbol] = this.bless(pointer); - instance[uniffiTypeNameSymbol] = 'Calculator'; - return instance; - }, - - bless(p: UnsafeMutableRawPointer): UniffiRustArcPtr { - return uniffiCaller.rustCall( - /*caller:*/ (status) => - nativeModule().ubrn_uniffi_internal_fn_method_calculator_ffi__bless_pointer( - p, - status - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - unbless(ptr: UniffiRustArcPtr) { - ptr.markDestroyed(); - }, - - pointer(obj: CalculatorInterface): UnsafeMutableRawPointer { - if ((obj as any)[destructorGuardSymbol] === undefined) { - throw new UniffiInternalError.UnexpectedNullPointer(); - } - return (obj as any)[pointerLiteralSymbol]; - }, - - clonePointer(obj: CalculatorInterface): UnsafeMutableRawPointer { - const pointer = this.pointer(obj); - return uniffiCaller.rustCall( - /*caller:*/ (callStatus) => - nativeModule().ubrn_uniffi_foobar_fn_clone_calculator( - pointer, - callStatus - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - freePointer(pointer: UnsafeMutableRawPointer): void { - uniffiCaller.rustCall( - /*caller:*/ (callStatus) => - nativeModule().ubrn_uniffi_foobar_fn_free_calculator( - pointer, - callStatus - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - isConcreteType(obj: any): obj is CalculatorInterface { - return ( - obj[destructorGuardSymbol] && - obj[uniffiTypeNameSymbol] === 'Calculator' - ); - }, - }; - })(); -// FfiConverter for CalculatorInterface -const FfiConverterTypeCalculator = new FfiConverterObject( - uniffiTypeCalculatorObjectFactory -); - -export interface SafeAdditionInterface { - perform(lhs: /*i64*/ bigint, rhs: /*i64*/ bigint) /*throws*/ : /*i64*/ bigint; -} - -export class SafeAddition - extends UniffiAbstractObject - implements SafeAdditionInterface -{ - readonly [uniffiTypeNameSymbol] = 'SafeAddition'; - readonly [destructorGuardSymbol]: UniffiRustArcPtr; - readonly [pointerLiteralSymbol]: UnsafeMutableRawPointer; - constructor() { - super(); - const pointer = uniffiCaller.rustCall( - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_constructor_safeaddition_new( - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ); - this[pointerLiteralSymbol] = pointer; - this[destructorGuardSymbol] = - uniffiTypeSafeAdditionObjectFactory.bless(pointer); - } - - public perform( - lhs: /*i64*/ bigint, - rhs: /*i64*/ bigint - ): /*i64*/ bigint /*throws*/ { - return FfiConverterInt64.lift( - uniffiCaller.rustCallWithError( - /*liftError:*/ FfiConverterTypeComputationError.lift.bind( - FfiConverterTypeComputationError - ), - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_method_safeaddition_perform( - uniffiTypeSafeAdditionObjectFactory.clonePointer(this), - FfiConverterInt64.lower(lhs), - FfiConverterInt64.lower(rhs), - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ) - ); - } - - /** - * {@inheritDoc uniffi-bindgen-react-native#UniffiAbstractObject.uniffiDestroy} - */ - uniffiDestroy(): void { - const ptr = (this as any)[destructorGuardSymbol]; - if (ptr !== undefined) { - const pointer = uniffiTypeSafeAdditionObjectFactory.pointer(this); - uniffiTypeSafeAdditionObjectFactory.freePointer(pointer); - uniffiTypeSafeAdditionObjectFactory.unbless(ptr); - delete (this as any)[destructorGuardSymbol]; - } - } - - static instanceOf(obj: any): obj is SafeAddition { - return uniffiTypeSafeAdditionObjectFactory.isConcreteType(obj); - } -} - -const uniffiTypeSafeAdditionObjectFactory: UniffiObjectFactory = - (() => { - return { - create(pointer: UnsafeMutableRawPointer): SafeAdditionInterface { - const instance = Object.create(SafeAddition.prototype); - instance[pointerLiteralSymbol] = pointer; - instance[destructorGuardSymbol] = this.bless(pointer); - instance[uniffiTypeNameSymbol] = 'SafeAddition'; - return instance; - }, - - bless(p: UnsafeMutableRawPointer): UniffiRustArcPtr { - return uniffiCaller.rustCall( - /*caller:*/ (status) => - nativeModule().ubrn_uniffi_internal_fn_method_safeaddition_ffi__bless_pointer( - p, - status - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - unbless(ptr: UniffiRustArcPtr) { - ptr.markDestroyed(); - }, - - pointer(obj: SafeAdditionInterface): UnsafeMutableRawPointer { - if ((obj as any)[destructorGuardSymbol] === undefined) { - throw new UniffiInternalError.UnexpectedNullPointer(); - } - return (obj as any)[pointerLiteralSymbol]; - }, - - clonePointer(obj: SafeAdditionInterface): UnsafeMutableRawPointer { - const pointer = this.pointer(obj); - return uniffiCaller.rustCall( - /*caller:*/ (callStatus) => - nativeModule().ubrn_uniffi_foobar_fn_clone_safeaddition( - pointer, - callStatus - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - freePointer(pointer: UnsafeMutableRawPointer): void { - uniffiCaller.rustCall( - /*caller:*/ (callStatus) => - nativeModule().ubrn_uniffi_foobar_fn_free_safeaddition( - pointer, - callStatus - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - isConcreteType(obj: any): obj is SafeAdditionInterface { - return ( - obj[destructorGuardSymbol] && - obj[uniffiTypeNameSymbol] === 'SafeAddition' - ); - }, - }; - })(); -// FfiConverter for SafeAdditionInterface -const FfiConverterTypeSafeAddition = new FfiConverterObject( - uniffiTypeSafeAdditionObjectFactory -); - -export interface SafeDivisionInterface { - perform(lhs: /*i64*/ bigint, rhs: /*i64*/ bigint) /*throws*/ : /*i64*/ bigint; -} - -export class SafeDivision - extends UniffiAbstractObject - implements SafeDivisionInterface -{ - readonly [uniffiTypeNameSymbol] = 'SafeDivision'; - readonly [destructorGuardSymbol]: UniffiRustArcPtr; - readonly [pointerLiteralSymbol]: UnsafeMutableRawPointer; - constructor() { - super(); - const pointer = uniffiCaller.rustCall( - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_constructor_safedivision_new( - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ); - this[pointerLiteralSymbol] = pointer; - this[destructorGuardSymbol] = - uniffiTypeSafeDivisionObjectFactory.bless(pointer); - } - - public perform( - lhs: /*i64*/ bigint, - rhs: /*i64*/ bigint - ): /*i64*/ bigint /*throws*/ { - return FfiConverterInt64.lift( - uniffiCaller.rustCallWithError( - /*liftError:*/ FfiConverterTypeComputationError.lift.bind( - FfiConverterTypeComputationError - ), - /*caller:*/ (callStatus) => { - return nativeModule().ubrn_uniffi_foobar_fn_method_safedivision_perform( - uniffiTypeSafeDivisionObjectFactory.clonePointer(this), - FfiConverterInt64.lower(lhs), - FfiConverterInt64.lower(rhs), - callStatus - ); - }, - /*liftString:*/ FfiConverterString.lift - ) - ); - } - - /** - * {@inheritDoc uniffi-bindgen-react-native#UniffiAbstractObject.uniffiDestroy} - */ - uniffiDestroy(): void { - const ptr = (this as any)[destructorGuardSymbol]; - if (ptr !== undefined) { - const pointer = uniffiTypeSafeDivisionObjectFactory.pointer(this); - uniffiTypeSafeDivisionObjectFactory.freePointer(pointer); - uniffiTypeSafeDivisionObjectFactory.unbless(ptr); - delete (this as any)[destructorGuardSymbol]; - } - } - - static instanceOf(obj: any): obj is SafeDivision { - return uniffiTypeSafeDivisionObjectFactory.isConcreteType(obj); - } -} - -const uniffiTypeSafeDivisionObjectFactory: UniffiObjectFactory = - (() => { - return { - create(pointer: UnsafeMutableRawPointer): SafeDivisionInterface { - const instance = Object.create(SafeDivision.prototype); - instance[pointerLiteralSymbol] = pointer; - instance[destructorGuardSymbol] = this.bless(pointer); - instance[uniffiTypeNameSymbol] = 'SafeDivision'; - return instance; - }, - - bless(p: UnsafeMutableRawPointer): UniffiRustArcPtr { - return uniffiCaller.rustCall( - /*caller:*/ (status) => - nativeModule().ubrn_uniffi_internal_fn_method_safedivision_ffi__bless_pointer( - p, - status - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - unbless(ptr: UniffiRustArcPtr) { - ptr.markDestroyed(); - }, - - pointer(obj: SafeDivisionInterface): UnsafeMutableRawPointer { - if ((obj as any)[destructorGuardSymbol] === undefined) { - throw new UniffiInternalError.UnexpectedNullPointer(); - } - return (obj as any)[pointerLiteralSymbol]; - }, - - clonePointer(obj: SafeDivisionInterface): UnsafeMutableRawPointer { - const pointer = this.pointer(obj); - return uniffiCaller.rustCall( - /*caller:*/ (callStatus) => - nativeModule().ubrn_uniffi_foobar_fn_clone_safedivision( - pointer, - callStatus - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - freePointer(pointer: UnsafeMutableRawPointer): void { - uniffiCaller.rustCall( - /*caller:*/ (callStatus) => - nativeModule().ubrn_uniffi_foobar_fn_free_safedivision( - pointer, - callStatus - ), - /*liftString:*/ FfiConverterString.lift - ); - }, - - isConcreteType(obj: any): obj is SafeDivisionInterface { - return ( - obj[destructorGuardSymbol] && - obj[uniffiTypeNameSymbol] === 'SafeDivision' - ); - }, - }; - })(); -// FfiConverter for SafeDivisionInterface -const FfiConverterTypeSafeDivision = new FfiConverterObject( - uniffiTypeSafeDivisionObjectFactory -); - -// FfiConverter for ComputationResult | undefined -const FfiConverterOptionalTypeComputationResult = new FfiConverterOptional( - FfiConverterTypeComputationResult -); - -/** - * This should be called before anything else. - * - * It is likely that this is being done for you by the library's `index.ts`. - * - * It checks versions of uniffi between when the Rust scaffolding was generated - * and when the bindings were generated. - * - * It also initializes the machinery to enable Rust to talk back to Javascript. - */ -function uniffiEnsureInitialized() { - // Get the bindings contract version from our ComponentInterface - const bindingsContractVersion = 29; - // Get the scaffolding contract version by calling the into the dylib - const scaffoldingContractVersion = - nativeModule().ubrn_ffi_foobar_uniffi_contract_version(); - if (bindingsContractVersion !== scaffoldingContractVersion) { - throw new UniffiInternalError.ContractVersionMismatch( - scaffoldingContractVersion, - bindingsContractVersion - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_func_safe_addition_operator() !== - 2550 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_func_safe_addition_operator' - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_func_safe_division_operator() !== - 26772 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_func_safe_division_operator' - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_method_binaryoperator_perform() !== - 14159 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_method_binaryoperator_perform' - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_method_calculator_calculate() !== - 63226 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_method_calculator_calculate' - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_method_calculator_calculate_more() !== - 55050 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_method_calculator_calculate_more' - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_method_calculator_last_result() !== - 48598 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_method_calculator_last_result' - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_method_safeaddition_perform() !== - 41639 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_method_safeaddition_perform' - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_method_safedivision_perform() !== - 11259 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_method_safedivision_perform' - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_constructor_calculator_new() !== - 50473 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_constructor_calculator_new' - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_constructor_safeaddition_new() !== - 7323 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_constructor_safeaddition_new' - ); - } - if ( - nativeModule().ubrn_uniffi_foobar_checksum_constructor_safedivision_new() !== - 18654 - ) { - throw new UniffiInternalError.ApiChecksumMismatch( - 'uniffi_foobar_checksum_constructor_safedivision_new' - ); - } - - uniffiCallbackInterfaceBinaryOperator.register(); -} - -export default Object.freeze({ - initialize: uniffiEnsureInitialized, - converters: { - FfiConverterTypeBinaryOperator, - FfiConverterTypeCalculator, - FfiConverterTypeComputationError, - FfiConverterTypeComputationResult, - FfiConverterTypeComputationState, - FfiConverterTypeSafeAddition, - FfiConverterTypeSafeDivision, - }, -}); diff --git a/packages/react-native-uniffi-russh/src/index.tsx b/packages/react-native-uniffi-russh/src/index.tsx deleted file mode 100644 index 70beffa..0000000 --- a/packages/react-native-uniffi-russh/src/index.tsx +++ /dev/null @@ -1,40 +0,0 @@ -// Generated by uniffi-bindgen-react-native -import installer from './NativeUniffiRussh'; - -// Register the rust crate with Hermes -// - the boolean flag ensures this loads exactly once, even if the JS -// code is reloaded (e.g. during development with metro). -let rustInstalled = false; -if (!rustInstalled) { - installer.installRustCrate(); - rustInstalled = true; -} - -// Export the generated bindings to the app. -export * from './generated/foobar'; - -// Now import the bindings so we can: -// - intialize them -// - export them as namespaced objects as the default export. -import * as foobar from './generated/foobar'; - -// Initialize the generated bindings: mostly checksums, but also callbacks. -// - the boolean flag ensures this loads exactly once, even if the JS code -// is reloaded (e.g. during development with metro). -let initialized = false; -if (!initialized) { - foobar.default.initialize(); - initialized = true; -} - -// This provides parity with the index.web.ts version of this file. -// The web version relies on an asynchronous fetch, which this doesn't -// need, so we just no-op. -export async function uniffiInitAsync() { - // NOOP. -} - -// Export the crates as individually namespaced objects. -export default { - foobar, -}; diff --git a/packages/react-native-uniffi-russh/tsconfig.json b/packages/react-native-uniffi-russh/tsconfig.json index cf07425..dab4e75 100644 --- a/packages/react-native-uniffi-russh/tsconfig.json +++ b/packages/react-native-uniffi-russh/tsconfig.json @@ -28,6 +28,5 @@ "verbatimModuleSyntax": true, "noUnusedLocals": false, "noUnusedParameters": false - }, - "exclude": ["**/node_modules"] + } }