@apollohg/react-native-rich-text-editor-code-highlighting 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/LICENSE +160 -0
  2. package/NativeEditorCodeHighlighting.podspec +24 -0
  3. package/README.md +47 -0
  4. package/RUST-STANDARD-LIBRARY-NOTICES.html +8266 -0
  5. package/THIRD_PARTY_NOTICES.md +18451 -0
  6. package/android/build.gradle +25 -0
  7. package/android/consumer-rules.pro +1 -0
  8. package/android/src/main/AndroidManifest.xml +1 -0
  9. package/android/src/main/java/com/apollohg/editor/highlighting/NativeCodeHighlightingModule.kt +17 -0
  10. package/android/src/main/java/com/apollohg/editor/highlighting/SyntectHighlightingProvider.kt +23 -0
  11. package/android/src/main/java/uniffi/native_editor_highlighting/native_editor_highlighting.kt +1259 -0
  12. package/android/src/main/jniLibs/arm64-v8a/libnative_editor_highlighting.so +0 -0
  13. package/android/src/main/jniLibs/armeabi-v7a/libnative_editor_highlighting.so +0 -0
  14. package/android/src/main/jniLibs/x86/libnative_editor_highlighting.so +0 -0
  15. package/android/src/main/jniLibs/x86_64/libnative_editor_highlighting.so +0 -0
  16. package/dist/index.d.ts +7 -0
  17. package/dist/index.js +25 -0
  18. package/expo-module.config.json +10 -0
  19. package/ios/Generated_highlighting.swift +728 -0
  20. package/ios/NativeCodeHighlightingModule.swift +14 -0
  21. package/ios/NativeEditorHighlighting.xcframework/Info.plist +44 -0
  22. package/ios/NativeEditorHighlighting.xcframework/ios-arm64/libnative_editor_highlighting.a +0 -0
  23. package/ios/NativeEditorHighlighting.xcframework/ios-arm64_x86_64-simulator/libnative_editor_highlighting.a +0 -0
  24. package/ios/SyntectHighlightingProvider.swift +12 -0
  25. package/ios/native_editor_highlightingFFI/module.modulemap +7 -0
  26. package/ios/native_editor_highlightingFFI/native_editor_highlightingFFI.h +551 -0
  27. package/package.json +49 -0
  28. package/scripts/verify-package.mjs +19 -0
  29. package/src/index.ts +41 -0
@@ -0,0 +1,1259 @@
1
+ // This file was autogenerated by some hot garbage in the `uniffi` crate.
2
+ // Trust me, you don't want to mess with it!
3
+
4
+ @file:Suppress("NAME_SHADOWING")
5
+
6
+ package uniffi.native_editor_highlighting
7
+
8
+ // Common helper code.
9
+ //
10
+ // Ideally this would live in a separate .kt file where it can be unittested etc
11
+ // in isolation, and perhaps even published as a re-useable package.
12
+ //
13
+ // However, it's important that the details of how this helper code works (e.g. the
14
+ // way that different builtin types are passed across the FFI) exactly match what's
15
+ // expected by the Rust code on the other side of the interface. In practice right
16
+ // now that means coming from the exact some version of `uniffi` that was used to
17
+ // compile the Rust component. The easiest way to ensure this is to bundle the Kotlin
18
+ // helpers directly inline like we're doing here.
19
+
20
+ import com.sun.jna.Library
21
+ import com.sun.jna.IntegerType
22
+ import com.sun.jna.Native
23
+ import com.sun.jna.Pointer
24
+ import com.sun.jna.Structure
25
+ import com.sun.jna.Callback
26
+ import com.sun.jna.ptr.*
27
+ import java.nio.ByteBuffer
28
+ import java.nio.ByteOrder
29
+ import java.nio.CharBuffer
30
+ import java.nio.charset.CodingErrorAction
31
+ import java.util.concurrent.atomic.AtomicLong
32
+ import java.util.concurrent.ConcurrentHashMap
33
+
34
+ // This is a helper for safely working with byte buffers returned from the Rust code.
35
+ // A rust-owned buffer is represented by its capacity, its current length, and a
36
+ // pointer to the underlying data.
37
+
38
+ /**
39
+ * @suppress
40
+ */
41
+ @Structure.FieldOrder("capacity", "len", "data")
42
+ open class RustBuffer : Structure() {
43
+ // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
44
+ // When dealing with these fields, make sure to call `toULong()`.
45
+ @JvmField var capacity: Long = 0
46
+ @JvmField var len: Long = 0
47
+ @JvmField var data: Pointer? = null
48
+
49
+ class ByValue: RustBuffer(), Structure.ByValue
50
+ class ByReference: RustBuffer(), Structure.ByReference
51
+
52
+ internal fun setValue(other: RustBuffer) {
53
+ capacity = other.capacity
54
+ len = other.len
55
+ data = other.data
56
+ }
57
+
58
+ companion object {
59
+ internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status ->
60
+ // Note: need to convert the size to a `Long` value to make this work with JVM.
61
+ UniffiLib.INSTANCE.ffi_native_editor_highlighting_rustbuffer_alloc(size.toLong(), status)
62
+ }.also {
63
+ if(it.data == null) {
64
+ throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
65
+ }
66
+ }
67
+
68
+ internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue {
69
+ var buf = RustBuffer.ByValue()
70
+ buf.capacity = capacity.toLong()
71
+ buf.len = len.toLong()
72
+ buf.data = data
73
+ return buf
74
+ }
75
+
76
+ internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status ->
77
+ UniffiLib.INSTANCE.ffi_native_editor_highlighting_rustbuffer_free(buf, status)
78
+ }
79
+ }
80
+
81
+ @Suppress("TooGenericExceptionThrown")
82
+ fun asByteBuffer() =
83
+ this.data?.getByteBuffer(0, this.len.toLong())?.also {
84
+ it.order(ByteOrder.BIG_ENDIAN)
85
+ }
86
+ }
87
+
88
+ /**
89
+ * The equivalent of the `*mut RustBuffer` type.
90
+ * Required for callbacks taking in an out pointer.
91
+ *
92
+ * Size is the sum of all values in the struct.
93
+ *
94
+ * @suppress
95
+ */
96
+ class RustBufferByReference : ByReference(16) {
97
+ /**
98
+ * Set the pointed-to `RustBuffer` to the given value.
99
+ */
100
+ fun setValue(value: RustBuffer.ByValue) {
101
+ // NOTE: The offsets are as they are in the C-like struct.
102
+ val pointer = getPointer()
103
+ pointer.setLong(0, value.capacity)
104
+ pointer.setLong(8, value.len)
105
+ pointer.setPointer(16, value.data)
106
+ }
107
+
108
+ /**
109
+ * Get a `RustBuffer.ByValue` from this reference.
110
+ */
111
+ fun getValue(): RustBuffer.ByValue {
112
+ val pointer = getPointer()
113
+ val value = RustBuffer.ByValue()
114
+ value.writeField("capacity", pointer.getLong(0))
115
+ value.writeField("len", pointer.getLong(8))
116
+ value.writeField("data", pointer.getLong(16))
117
+
118
+ return value
119
+ }
120
+ }
121
+
122
+ // This is a helper for safely passing byte references into the rust code.
123
+ // It's not actually used at the moment, because there aren't many things that you
124
+ // can take a direct pointer to in the JVM, and if we're going to copy something
125
+ // then we might as well copy it into a `RustBuffer`. But it's here for API
126
+ // completeness.
127
+
128
+ @Structure.FieldOrder("len", "data")
129
+ internal open class ForeignBytes : Structure() {
130
+ @JvmField var len: Int = 0
131
+ @JvmField var data: Pointer? = null
132
+
133
+ class ByValue : ForeignBytes(), Structure.ByValue
134
+ }
135
+ /**
136
+ * The FfiConverter interface handles converter types to and from the FFI
137
+ *
138
+ * All implementing objects should be public to support external types. When a
139
+ * type is external we need to import it's FfiConverter.
140
+ *
141
+ * @suppress
142
+ */
143
+ public interface FfiConverter<KotlinType, FfiType> {
144
+ // Convert an FFI type to a Kotlin type
145
+ fun lift(value: FfiType): KotlinType
146
+
147
+ // Convert an Kotlin type to an FFI type
148
+ fun lower(value: KotlinType): FfiType
149
+
150
+ // Read a Kotlin type from a `ByteBuffer`
151
+ fun read(buf: ByteBuffer): KotlinType
152
+
153
+ // Calculate bytes to allocate when creating a `RustBuffer`
154
+ //
155
+ // This must return at least as many bytes as the write() function will
156
+ // write. It can return more bytes than needed, for example when writing
157
+ // Strings we can't know the exact bytes needed until we the UTF-8
158
+ // encoding, so we pessimistically allocate the largest size possible (3
159
+ // bytes per codepoint). Allocating extra bytes is not really a big deal
160
+ // because the `RustBuffer` is short-lived.
161
+ fun allocationSize(value: KotlinType): ULong
162
+
163
+ // Write a Kotlin type to a `ByteBuffer`
164
+ fun write(value: KotlinType, buf: ByteBuffer)
165
+
166
+ // Lower a value into a `RustBuffer`
167
+ //
168
+ // This method lowers a value into a `RustBuffer` rather than the normal
169
+ // FfiType. It's used by the callback interface code. Callback interface
170
+ // returns are always serialized into a `RustBuffer` regardless of their
171
+ // normal FFI type.
172
+ fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
173
+ val rbuf = RustBuffer.alloc(allocationSize(value))
174
+ try {
175
+ val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also {
176
+ it.order(ByteOrder.BIG_ENDIAN)
177
+ }
178
+ write(value, bbuf)
179
+ rbuf.writeField("len", bbuf.position().toLong())
180
+ return rbuf
181
+ } catch (e: Throwable) {
182
+ RustBuffer.free(rbuf)
183
+ throw e
184
+ }
185
+ }
186
+
187
+ // Lift a value from a `RustBuffer`.
188
+ //
189
+ // This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
190
+ // It's currently only used by the `FfiConverterRustBuffer` class below.
191
+ fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
192
+ val byteBuf = rbuf.asByteBuffer()!!
193
+ try {
194
+ val item = read(byteBuf)
195
+ if (byteBuf.hasRemaining()) {
196
+ throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
197
+ }
198
+ return item
199
+ } finally {
200
+ RustBuffer.free(rbuf)
201
+ }
202
+ }
203
+ }
204
+
205
+ /**
206
+ * FfiConverter that uses `RustBuffer` as the FfiType
207
+ *
208
+ * @suppress
209
+ */
210
+ public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
211
+ override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
212
+ override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
213
+ }
214
+ // A handful of classes and functions to support the generated data structures.
215
+ // This would be a good candidate for isolating in its own ffi-support lib.
216
+
217
+ internal const val UNIFFI_CALL_SUCCESS = 0.toByte()
218
+ internal const val UNIFFI_CALL_ERROR = 1.toByte()
219
+ internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte()
220
+
221
+ @Structure.FieldOrder("code", "error_buf")
222
+ internal open class UniffiRustCallStatus : Structure() {
223
+ @JvmField var code: Byte = 0
224
+ @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
225
+
226
+ class ByValue: UniffiRustCallStatus(), Structure.ByValue
227
+
228
+ fun isSuccess(): Boolean {
229
+ return code == UNIFFI_CALL_SUCCESS
230
+ }
231
+
232
+ fun isError(): Boolean {
233
+ return code == UNIFFI_CALL_ERROR
234
+ }
235
+
236
+ fun isPanic(): Boolean {
237
+ return code == UNIFFI_CALL_UNEXPECTED_ERROR
238
+ }
239
+
240
+ companion object {
241
+ fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue {
242
+ val callStatus = UniffiRustCallStatus.ByValue()
243
+ callStatus.code = code
244
+ callStatus.error_buf = errorBuf
245
+ return callStatus
246
+ }
247
+ }
248
+ }
249
+
250
+ class InternalException(message: String) : kotlin.Exception(message)
251
+
252
+ /**
253
+ * Each top-level error class has a companion object that can lift the error from the call status's rust buffer
254
+ *
255
+ * @suppress
256
+ */
257
+ interface UniffiRustCallStatusErrorHandler<E> {
258
+ fun lift(error_buf: RustBuffer.ByValue): E;
259
+ }
260
+
261
+ // Helpers for calling Rust
262
+ // In practice we usually need to be synchronized to call this safely, so it doesn't
263
+ // synchronize itself
264
+
265
+ // Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err
266
+ private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U {
267
+ var status = UniffiRustCallStatus()
268
+ val return_value = callback(status)
269
+ uniffiCheckCallStatus(errorHandler, status)
270
+ return return_value
271
+ }
272
+
273
+ // Check UniffiRustCallStatus and throw an error if the call wasn't successful
274
+ private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) {
275
+ if (status.isSuccess()) {
276
+ return
277
+ } else if (status.isError()) {
278
+ throw errorHandler.lift(status.error_buf)
279
+ } else if (status.isPanic()) {
280
+ // when the rust code sees a panic, it tries to construct a rustbuffer
281
+ // with the message. but if that code panics, then it just sends back
282
+ // an empty buffer.
283
+ if (status.error_buf.len > 0) {
284
+ throw InternalException(FfiConverterString.lift(status.error_buf))
285
+ } else {
286
+ throw InternalException("Rust panic")
287
+ }
288
+ } else {
289
+ throw InternalException("Unknown rust call status: $status.code")
290
+ }
291
+ }
292
+
293
+ /**
294
+ * UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
295
+ *
296
+ * @suppress
297
+ */
298
+ object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
299
+ override fun lift(error_buf: RustBuffer.ByValue): InternalException {
300
+ RustBuffer.free(error_buf)
301
+ return InternalException("Unexpected CALL_ERROR")
302
+ }
303
+ }
304
+
305
+ // Call a rust function that returns a plain value
306
+ private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U {
307
+ return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback)
308
+ }
309
+
310
+ internal inline fun<T> uniffiTraitInterfaceCall(
311
+ callStatus: UniffiRustCallStatus,
312
+ makeCall: () -> T,
313
+ writeReturn: (T) -> Unit,
314
+ ) {
315
+ try {
316
+ writeReturn(makeCall())
317
+ } catch(e: kotlin.Exception) {
318
+ callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
319
+ callStatus.error_buf = FfiConverterString.lower(e.toString())
320
+ }
321
+ }
322
+
323
+ internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
324
+ callStatus: UniffiRustCallStatus,
325
+ makeCall: () -> T,
326
+ writeReturn: (T) -> Unit,
327
+ lowerError: (E) -> RustBuffer.ByValue
328
+ ) {
329
+ try {
330
+ writeReturn(makeCall())
331
+ } catch(e: kotlin.Exception) {
332
+ if (e is E) {
333
+ callStatus.code = UNIFFI_CALL_ERROR
334
+ callStatus.error_buf = lowerError(e)
335
+ } else {
336
+ callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
337
+ callStatus.error_buf = FfiConverterString.lower(e.toString())
338
+ }
339
+ }
340
+ }
341
+ // Map handles to objects
342
+ //
343
+ // This is used pass an opaque 64-bit handle representing a foreign object to the Rust code.
344
+ internal class UniffiHandleMap<T: Any> {
345
+ private val map = ConcurrentHashMap<Long, T>()
346
+ private val counter = java.util.concurrent.atomic.AtomicLong(0)
347
+
348
+ val size: Int
349
+ get() = map.size
350
+
351
+ // Insert a new object into the handle map and get a handle for it
352
+ fun insert(obj: T): Long {
353
+ val handle = counter.getAndAdd(1)
354
+ map.put(handle, obj)
355
+ return handle
356
+ }
357
+
358
+ // Get an object from the handle map
359
+ fun get(handle: Long): T {
360
+ return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle")
361
+ }
362
+
363
+ // Remove an entry from the handlemap and get the Kotlin object back
364
+ fun remove(handle: Long): T {
365
+ return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle")
366
+ }
367
+ }
368
+
369
+ // Contains loading, initialization code,
370
+ // and the FFI Function declarations in a com.sun.jna.Library.
371
+ @Synchronized
372
+ private fun findLibraryName(componentName: String): String {
373
+ val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
374
+ if (libOverride != null) {
375
+ return libOverride
376
+ }
377
+ return "native_editor_highlighting"
378
+ }
379
+
380
+ private inline fun <reified Lib : Library> loadIndirect(
381
+ componentName: String
382
+ ): Lib {
383
+ return Native.load<Lib>(findLibraryName(componentName), Lib::class.java)
384
+ }
385
+
386
+ // Define FFI callback types
387
+ internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback {
388
+ fun callback(`data`: Long,`pollResult`: Byte,)
389
+ }
390
+ internal interface UniffiForeignFutureFree : com.sun.jna.Callback {
391
+ fun callback(`handle`: Long,)
392
+ }
393
+ internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback {
394
+ fun callback(`handle`: Long,)
395
+ }
396
+ @Structure.FieldOrder("handle", "free")
397
+ internal open class UniffiForeignFuture(
398
+ @JvmField internal var `handle`: Long = 0.toLong(),
399
+ @JvmField internal var `free`: UniffiForeignFutureFree? = null,
400
+ ) : Structure() {
401
+ class UniffiByValue(
402
+ `handle`: Long = 0.toLong(),
403
+ `free`: UniffiForeignFutureFree? = null,
404
+ ): UniffiForeignFuture(`handle`,`free`,), Structure.ByValue
405
+
406
+ internal fun uniffiSetValue(other: UniffiForeignFuture) {
407
+ `handle` = other.`handle`
408
+ `free` = other.`free`
409
+ }
410
+
411
+ }
412
+ @Structure.FieldOrder("returnValue", "callStatus")
413
+ internal open class UniffiForeignFutureStructU8(
414
+ @JvmField internal var `returnValue`: Byte = 0.toByte(),
415
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
416
+ ) : Structure() {
417
+ class UniffiByValue(
418
+ `returnValue`: Byte = 0.toByte(),
419
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
420
+ ): UniffiForeignFutureStructU8(`returnValue`,`callStatus`,), Structure.ByValue
421
+
422
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU8) {
423
+ `returnValue` = other.`returnValue`
424
+ `callStatus` = other.`callStatus`
425
+ }
426
+
427
+ }
428
+ internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback {
429
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU8.UniffiByValue,)
430
+ }
431
+ @Structure.FieldOrder("returnValue", "callStatus")
432
+ internal open class UniffiForeignFutureStructI8(
433
+ @JvmField internal var `returnValue`: Byte = 0.toByte(),
434
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
435
+ ) : Structure() {
436
+ class UniffiByValue(
437
+ `returnValue`: Byte = 0.toByte(),
438
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
439
+ ): UniffiForeignFutureStructI8(`returnValue`,`callStatus`,), Structure.ByValue
440
+
441
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI8) {
442
+ `returnValue` = other.`returnValue`
443
+ `callStatus` = other.`callStatus`
444
+ }
445
+
446
+ }
447
+ internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback {
448
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI8.UniffiByValue,)
449
+ }
450
+ @Structure.FieldOrder("returnValue", "callStatus")
451
+ internal open class UniffiForeignFutureStructU16(
452
+ @JvmField internal var `returnValue`: Short = 0.toShort(),
453
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
454
+ ) : Structure() {
455
+ class UniffiByValue(
456
+ `returnValue`: Short = 0.toShort(),
457
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
458
+ ): UniffiForeignFutureStructU16(`returnValue`,`callStatus`,), Structure.ByValue
459
+
460
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU16) {
461
+ `returnValue` = other.`returnValue`
462
+ `callStatus` = other.`callStatus`
463
+ }
464
+
465
+ }
466
+ internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback {
467
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU16.UniffiByValue,)
468
+ }
469
+ @Structure.FieldOrder("returnValue", "callStatus")
470
+ internal open class UniffiForeignFutureStructI16(
471
+ @JvmField internal var `returnValue`: Short = 0.toShort(),
472
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
473
+ ) : Structure() {
474
+ class UniffiByValue(
475
+ `returnValue`: Short = 0.toShort(),
476
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
477
+ ): UniffiForeignFutureStructI16(`returnValue`,`callStatus`,), Structure.ByValue
478
+
479
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI16) {
480
+ `returnValue` = other.`returnValue`
481
+ `callStatus` = other.`callStatus`
482
+ }
483
+
484
+ }
485
+ internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback {
486
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI16.UniffiByValue,)
487
+ }
488
+ @Structure.FieldOrder("returnValue", "callStatus")
489
+ internal open class UniffiForeignFutureStructU32(
490
+ @JvmField internal var `returnValue`: Int = 0,
491
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
492
+ ) : Structure() {
493
+ class UniffiByValue(
494
+ `returnValue`: Int = 0,
495
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
496
+ ): UniffiForeignFutureStructU32(`returnValue`,`callStatus`,), Structure.ByValue
497
+
498
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU32) {
499
+ `returnValue` = other.`returnValue`
500
+ `callStatus` = other.`callStatus`
501
+ }
502
+
503
+ }
504
+ internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback {
505
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU32.UniffiByValue,)
506
+ }
507
+ @Structure.FieldOrder("returnValue", "callStatus")
508
+ internal open class UniffiForeignFutureStructI32(
509
+ @JvmField internal var `returnValue`: Int = 0,
510
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
511
+ ) : Structure() {
512
+ class UniffiByValue(
513
+ `returnValue`: Int = 0,
514
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
515
+ ): UniffiForeignFutureStructI32(`returnValue`,`callStatus`,), Structure.ByValue
516
+
517
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI32) {
518
+ `returnValue` = other.`returnValue`
519
+ `callStatus` = other.`callStatus`
520
+ }
521
+
522
+ }
523
+ internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback {
524
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI32.UniffiByValue,)
525
+ }
526
+ @Structure.FieldOrder("returnValue", "callStatus")
527
+ internal open class UniffiForeignFutureStructU64(
528
+ @JvmField internal var `returnValue`: Long = 0.toLong(),
529
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
530
+ ) : Structure() {
531
+ class UniffiByValue(
532
+ `returnValue`: Long = 0.toLong(),
533
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
534
+ ): UniffiForeignFutureStructU64(`returnValue`,`callStatus`,), Structure.ByValue
535
+
536
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU64) {
537
+ `returnValue` = other.`returnValue`
538
+ `callStatus` = other.`callStatus`
539
+ }
540
+
541
+ }
542
+ internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback {
543
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU64.UniffiByValue,)
544
+ }
545
+ @Structure.FieldOrder("returnValue", "callStatus")
546
+ internal open class UniffiForeignFutureStructI64(
547
+ @JvmField internal var `returnValue`: Long = 0.toLong(),
548
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
549
+ ) : Structure() {
550
+ class UniffiByValue(
551
+ `returnValue`: Long = 0.toLong(),
552
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
553
+ ): UniffiForeignFutureStructI64(`returnValue`,`callStatus`,), Structure.ByValue
554
+
555
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI64) {
556
+ `returnValue` = other.`returnValue`
557
+ `callStatus` = other.`callStatus`
558
+ }
559
+
560
+ }
561
+ internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback {
562
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI64.UniffiByValue,)
563
+ }
564
+ @Structure.FieldOrder("returnValue", "callStatus")
565
+ internal open class UniffiForeignFutureStructF32(
566
+ @JvmField internal var `returnValue`: Float = 0.0f,
567
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
568
+ ) : Structure() {
569
+ class UniffiByValue(
570
+ `returnValue`: Float = 0.0f,
571
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
572
+ ): UniffiForeignFutureStructF32(`returnValue`,`callStatus`,), Structure.ByValue
573
+
574
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructF32) {
575
+ `returnValue` = other.`returnValue`
576
+ `callStatus` = other.`callStatus`
577
+ }
578
+
579
+ }
580
+ internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback {
581
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF32.UniffiByValue,)
582
+ }
583
+ @Structure.FieldOrder("returnValue", "callStatus")
584
+ internal open class UniffiForeignFutureStructF64(
585
+ @JvmField internal var `returnValue`: Double = 0.0,
586
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
587
+ ) : Structure() {
588
+ class UniffiByValue(
589
+ `returnValue`: Double = 0.0,
590
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
591
+ ): UniffiForeignFutureStructF64(`returnValue`,`callStatus`,), Structure.ByValue
592
+
593
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructF64) {
594
+ `returnValue` = other.`returnValue`
595
+ `callStatus` = other.`callStatus`
596
+ }
597
+
598
+ }
599
+ internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback {
600
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF64.UniffiByValue,)
601
+ }
602
+ @Structure.FieldOrder("returnValue", "callStatus")
603
+ internal open class UniffiForeignFutureStructPointer(
604
+ @JvmField internal var `returnValue`: Pointer = Pointer.NULL,
605
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
606
+ ) : Structure() {
607
+ class UniffiByValue(
608
+ `returnValue`: Pointer = Pointer.NULL,
609
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
610
+ ): UniffiForeignFutureStructPointer(`returnValue`,`callStatus`,), Structure.ByValue
611
+
612
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructPointer) {
613
+ `returnValue` = other.`returnValue`
614
+ `callStatus` = other.`callStatus`
615
+ }
616
+
617
+ }
618
+ internal interface UniffiForeignFutureCompletePointer : com.sun.jna.Callback {
619
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructPointer.UniffiByValue,)
620
+ }
621
+ @Structure.FieldOrder("returnValue", "callStatus")
622
+ internal open class UniffiForeignFutureStructRustBuffer(
623
+ @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
624
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
625
+ ) : Structure() {
626
+ class UniffiByValue(
627
+ `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
628
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
629
+ ): UniffiForeignFutureStructRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue
630
+
631
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructRustBuffer) {
632
+ `returnValue` = other.`returnValue`
633
+ `callStatus` = other.`callStatus`
634
+ }
635
+
636
+ }
637
+ internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback {
638
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructRustBuffer.UniffiByValue,)
639
+ }
640
+ @Structure.FieldOrder("callStatus")
641
+ internal open class UniffiForeignFutureStructVoid(
642
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
643
+ ) : Structure() {
644
+ class UniffiByValue(
645
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
646
+ ): UniffiForeignFutureStructVoid(`callStatus`,), Structure.ByValue
647
+
648
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructVoid) {
649
+ `callStatus` = other.`callStatus`
650
+ }
651
+
652
+ }
653
+ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
654
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructVoid.UniffiByValue,)
655
+ }
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+
684
+
685
+
686
+
687
+
688
+
689
+
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+ // For large crates we prevent `MethodTooLargeException` (see #2340)
717
+ // N.B. the name of the extension is very misleading, since it is
718
+ // rather `InterfaceTooLargeException`, caused by too many methods
719
+ // in the interface for large crates.
720
+ //
721
+ // By splitting the otherwise huge interface into two parts
722
+ // * UniffiLib
723
+ // * IntegrityCheckingUniffiLib (this)
724
+ // we allow for ~2x as many methods in the UniffiLib interface.
725
+ //
726
+ // The `ffi_uniffi_contract_version` method and all checksum methods are put
727
+ // into `IntegrityCheckingUniffiLib` and these methods are called only once,
728
+ // when the library is loaded.
729
+ internal interface IntegrityCheckingUniffiLib : Library {
730
+ // Integrity check functions only
731
+ fun uniffi_native_editor_highlighting_checksum_func_highlight_code(
732
+ ): Short
733
+ fun ffi_native_editor_highlighting_uniffi_contract_version(
734
+ ): Int
735
+
736
+ }
737
+
738
+ // A JNA Library to expose the extern-C FFI definitions.
739
+ // This is an implementation detail which will be called internally by the public API.
740
+ internal interface UniffiLib : Library {
741
+ companion object {
742
+ internal val INSTANCE: UniffiLib by lazy {
743
+ val componentName = "native_editor_highlighting"
744
+ // For large crates we prevent `MethodTooLargeException` (see #2340)
745
+ // N.B. the name of the extension is very misleading, since it is
746
+ // rather `InterfaceTooLargeException`, caused by too many methods
747
+ // in the interface for large crates.
748
+ //
749
+ // By splitting the otherwise huge interface into two parts
750
+ // * UniffiLib (this)
751
+ // * IntegrityCheckingUniffiLib
752
+ // And all checksum methods are put into `IntegrityCheckingUniffiLib`
753
+ // we allow for ~2x as many methods in the UniffiLib interface.
754
+ //
755
+ // Thus we first load the library with `loadIndirect` as `IntegrityCheckingUniffiLib`
756
+ // so that we can (optionally!) call `uniffiCheckApiChecksums`...
757
+ loadIndirect<IntegrityCheckingUniffiLib>(componentName)
758
+ .also { lib: IntegrityCheckingUniffiLib ->
759
+ uniffiCheckContractApiVersion(lib)
760
+ uniffiCheckApiChecksums(lib)
761
+ }
762
+ // ... and then we load the library as `UniffiLib`
763
+ // N.B. we cannot use `loadIndirect` once and then try to cast it to `UniffiLib`
764
+ // => results in `java.lang.ClassCastException: com.sun.proxy.$Proxy cannot be cast to ...`
765
+ // error. So we must call `loadIndirect` twice. For crates large enough
766
+ // to trigger this issue, the performance impact is negligible, running on
767
+ // a macOS M1 machine the `loadIndirect` call takes ~50ms.
768
+ val lib = loadIndirect<UniffiLib>(componentName)
769
+ // No need to check the contract version and checksums, since
770
+ // we already did that with `IntegrityCheckingUniffiLib` above.
771
+ // Loading of library with integrity check done.
772
+ lib
773
+ }
774
+
775
+ }
776
+
777
+ // FFI functions
778
+ fun uniffi_native_editor_highlighting_fn_func_highlight_code(`text`: RustBuffer.ByValue,`language`: RustBuffer.ByValue,`theme`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
779
+ ): RustBuffer.ByValue
780
+ fun ffi_native_editor_highlighting_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus,
781
+ ): RustBuffer.ByValue
782
+ fun ffi_native_editor_highlighting_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus,
783
+ ): RustBuffer.ByValue
784
+ fun ffi_native_editor_highlighting_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
785
+ ): Unit
786
+ fun ffi_native_editor_highlighting_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus,
787
+ ): RustBuffer.ByValue
788
+ fun ffi_native_editor_highlighting_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
789
+ ): Unit
790
+ fun ffi_native_editor_highlighting_rust_future_cancel_u8(`handle`: Long,
791
+ ): Unit
792
+ fun ffi_native_editor_highlighting_rust_future_free_u8(`handle`: Long,
793
+ ): Unit
794
+ fun ffi_native_editor_highlighting_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
795
+ ): Byte
796
+ fun ffi_native_editor_highlighting_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
797
+ ): Unit
798
+ fun ffi_native_editor_highlighting_rust_future_cancel_i8(`handle`: Long,
799
+ ): Unit
800
+ fun ffi_native_editor_highlighting_rust_future_free_i8(`handle`: Long,
801
+ ): Unit
802
+ fun ffi_native_editor_highlighting_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
803
+ ): Byte
804
+ fun ffi_native_editor_highlighting_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
805
+ ): Unit
806
+ fun ffi_native_editor_highlighting_rust_future_cancel_u16(`handle`: Long,
807
+ ): Unit
808
+ fun ffi_native_editor_highlighting_rust_future_free_u16(`handle`: Long,
809
+ ): Unit
810
+ fun ffi_native_editor_highlighting_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
811
+ ): Short
812
+ fun ffi_native_editor_highlighting_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
813
+ ): Unit
814
+ fun ffi_native_editor_highlighting_rust_future_cancel_i16(`handle`: Long,
815
+ ): Unit
816
+ fun ffi_native_editor_highlighting_rust_future_free_i16(`handle`: Long,
817
+ ): Unit
818
+ fun ffi_native_editor_highlighting_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
819
+ ): Short
820
+ fun ffi_native_editor_highlighting_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
821
+ ): Unit
822
+ fun ffi_native_editor_highlighting_rust_future_cancel_u32(`handle`: Long,
823
+ ): Unit
824
+ fun ffi_native_editor_highlighting_rust_future_free_u32(`handle`: Long,
825
+ ): Unit
826
+ fun ffi_native_editor_highlighting_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
827
+ ): Int
828
+ fun ffi_native_editor_highlighting_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
829
+ ): Unit
830
+ fun ffi_native_editor_highlighting_rust_future_cancel_i32(`handle`: Long,
831
+ ): Unit
832
+ fun ffi_native_editor_highlighting_rust_future_free_i32(`handle`: Long,
833
+ ): Unit
834
+ fun ffi_native_editor_highlighting_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
835
+ ): Int
836
+ fun ffi_native_editor_highlighting_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
837
+ ): Unit
838
+ fun ffi_native_editor_highlighting_rust_future_cancel_u64(`handle`: Long,
839
+ ): Unit
840
+ fun ffi_native_editor_highlighting_rust_future_free_u64(`handle`: Long,
841
+ ): Unit
842
+ fun ffi_native_editor_highlighting_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
843
+ ): Long
844
+ fun ffi_native_editor_highlighting_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
845
+ ): Unit
846
+ fun ffi_native_editor_highlighting_rust_future_cancel_i64(`handle`: Long,
847
+ ): Unit
848
+ fun ffi_native_editor_highlighting_rust_future_free_i64(`handle`: Long,
849
+ ): Unit
850
+ fun ffi_native_editor_highlighting_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
851
+ ): Long
852
+ fun ffi_native_editor_highlighting_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
853
+ ): Unit
854
+ fun ffi_native_editor_highlighting_rust_future_cancel_f32(`handle`: Long,
855
+ ): Unit
856
+ fun ffi_native_editor_highlighting_rust_future_free_f32(`handle`: Long,
857
+ ): Unit
858
+ fun ffi_native_editor_highlighting_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
859
+ ): Float
860
+ fun ffi_native_editor_highlighting_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
861
+ ): Unit
862
+ fun ffi_native_editor_highlighting_rust_future_cancel_f64(`handle`: Long,
863
+ ): Unit
864
+ fun ffi_native_editor_highlighting_rust_future_free_f64(`handle`: Long,
865
+ ): Unit
866
+ fun ffi_native_editor_highlighting_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
867
+ ): Double
868
+ fun ffi_native_editor_highlighting_rust_future_poll_pointer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
869
+ ): Unit
870
+ fun ffi_native_editor_highlighting_rust_future_cancel_pointer(`handle`: Long,
871
+ ): Unit
872
+ fun ffi_native_editor_highlighting_rust_future_free_pointer(`handle`: Long,
873
+ ): Unit
874
+ fun ffi_native_editor_highlighting_rust_future_complete_pointer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
875
+ ): Pointer
876
+ fun ffi_native_editor_highlighting_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
877
+ ): Unit
878
+ fun ffi_native_editor_highlighting_rust_future_cancel_rust_buffer(`handle`: Long,
879
+ ): Unit
880
+ fun ffi_native_editor_highlighting_rust_future_free_rust_buffer(`handle`: Long,
881
+ ): Unit
882
+ fun ffi_native_editor_highlighting_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
883
+ ): RustBuffer.ByValue
884
+ fun ffi_native_editor_highlighting_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
885
+ ): Unit
886
+ fun ffi_native_editor_highlighting_rust_future_cancel_void(`handle`: Long,
887
+ ): Unit
888
+ fun ffi_native_editor_highlighting_rust_future_free_void(`handle`: Long,
889
+ ): Unit
890
+ fun ffi_native_editor_highlighting_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
891
+ ): Unit
892
+
893
+ }
894
+
895
+ private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) {
896
+ // Get the bindings contract version from our ComponentInterface
897
+ val bindings_contract_version = 29
898
+ // Get the scaffolding contract version by calling the into the dylib
899
+ val scaffolding_contract_version = lib.ffi_native_editor_highlighting_uniffi_contract_version()
900
+ if (bindings_contract_version != scaffolding_contract_version) {
901
+ throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
902
+ }
903
+ }
904
+ @Suppress("UNUSED_PARAMETER")
905
+ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) {
906
+ if (lib.uniffi_native_editor_highlighting_checksum_func_highlight_code() != 17678.toShort()) {
907
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
908
+ }
909
+ }
910
+
911
+ /**
912
+ * @suppress
913
+ */
914
+ public fun uniffiEnsureInitialized() {
915
+ UniffiLib.INSTANCE
916
+ }
917
+
918
+ // Async support
919
+
920
+ // Public interface members begin here.
921
+
922
+
923
+ // Interface implemented by anything that can contain an object reference.
924
+ //
925
+ // Such types expose a `destroy()` method that must be called to cleanly
926
+ // dispose of the contained objects. Failure to call this method may result
927
+ // in memory leaks.
928
+ //
929
+ // The easiest way to ensure this method is called is to use the `.use`
930
+ // helper method to execute a block and destroy the object at the end.
931
+ interface Disposable {
932
+ fun destroy()
933
+ companion object {
934
+ fun destroy(vararg args: Any?) {
935
+ for (arg in args) {
936
+ when (arg) {
937
+ is Disposable -> arg.destroy()
938
+ is ArrayList<*> -> {
939
+ for (idx in arg.indices) {
940
+ val element = arg[idx]
941
+ if (element is Disposable) {
942
+ element.destroy()
943
+ }
944
+ }
945
+ }
946
+ is Map<*, *> -> {
947
+ for (element in arg.values) {
948
+ if (element is Disposable) {
949
+ element.destroy()
950
+ }
951
+ }
952
+ }
953
+ is Iterable<*> -> {
954
+ for (element in arg) {
955
+ if (element is Disposable) {
956
+ element.destroy()
957
+ }
958
+ }
959
+ }
960
+ }
961
+ }
962
+ }
963
+ }
964
+ }
965
+
966
+ /**
967
+ * @suppress
968
+ */
969
+ inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
970
+ try {
971
+ block(this)
972
+ } finally {
973
+ try {
974
+ // N.B. our implementation is on the nullable type `Disposable?`.
975
+ this?.destroy()
976
+ } catch (e: Throwable) {
977
+ // swallow
978
+ }
979
+ }
980
+
981
+ /**
982
+ * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
983
+ *
984
+ * @suppress
985
+ * */
986
+ object NoPointer
987
+
988
+ /**
989
+ * @suppress
990
+ */
991
+ public object FfiConverterUByte: FfiConverter<UByte, Byte> {
992
+ override fun lift(value: Byte): UByte {
993
+ return value.toUByte()
994
+ }
995
+
996
+ override fun read(buf: ByteBuffer): UByte {
997
+ return lift(buf.get())
998
+ }
999
+
1000
+ override fun lower(value: UByte): Byte {
1001
+ return value.toByte()
1002
+ }
1003
+
1004
+ override fun allocationSize(value: UByte) = 1UL
1005
+
1006
+ override fun write(value: UByte, buf: ByteBuffer) {
1007
+ buf.put(value.toByte())
1008
+ }
1009
+ }
1010
+
1011
+ /**
1012
+ * @suppress
1013
+ */
1014
+ public object FfiConverterUInt: FfiConverter<UInt, Int> {
1015
+ override fun lift(value: Int): UInt {
1016
+ return value.toUInt()
1017
+ }
1018
+
1019
+ override fun read(buf: ByteBuffer): UInt {
1020
+ return lift(buf.getInt())
1021
+ }
1022
+
1023
+ override fun lower(value: UInt): Int {
1024
+ return value.toInt()
1025
+ }
1026
+
1027
+ override fun allocationSize(value: UInt) = 4UL
1028
+
1029
+ override fun write(value: UInt, buf: ByteBuffer) {
1030
+ buf.putInt(value.toInt())
1031
+ }
1032
+ }
1033
+
1034
+ /**
1035
+ * @suppress
1036
+ */
1037
+ public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
1038
+ // Note: we don't inherit from FfiConverterRustBuffer, because we use a
1039
+ // special encoding when lowering/lifting. We can use `RustBuffer.len` to
1040
+ // store our length and avoid writing it out to the buffer.
1041
+ override fun lift(value: RustBuffer.ByValue): String {
1042
+ try {
1043
+ val byteArr = ByteArray(value.len.toInt())
1044
+ value.asByteBuffer()!!.get(byteArr)
1045
+ return byteArr.toString(Charsets.UTF_8)
1046
+ } finally {
1047
+ RustBuffer.free(value)
1048
+ }
1049
+ }
1050
+
1051
+ override fun read(buf: ByteBuffer): String {
1052
+ val len = buf.getInt()
1053
+ val byteArr = ByteArray(len)
1054
+ buf.get(byteArr)
1055
+ return byteArr.toString(Charsets.UTF_8)
1056
+ }
1057
+
1058
+ fun toUtf8(value: String): ByteBuffer {
1059
+ // Make sure we don't have invalid UTF-16, check for lone surrogates.
1060
+ return Charsets.UTF_8.newEncoder().run {
1061
+ onMalformedInput(CodingErrorAction.REPORT)
1062
+ encode(CharBuffer.wrap(value))
1063
+ }
1064
+ }
1065
+
1066
+ override fun lower(value: String): RustBuffer.ByValue {
1067
+ val byteBuf = toUtf8(value)
1068
+ // Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
1069
+ // to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
1070
+ val rbuf = RustBuffer.alloc(byteBuf.limit().toULong())
1071
+ rbuf.asByteBuffer()!!.put(byteBuf)
1072
+ return rbuf
1073
+ }
1074
+
1075
+ // We aren't sure exactly how many bytes our string will be once it's UTF-8
1076
+ // encoded. Allocate 3 bytes per UTF-16 code unit which will always be
1077
+ // enough.
1078
+ override fun allocationSize(value: String): ULong {
1079
+ val sizeForLength = 4UL
1080
+ val sizeForString = value.length.toULong() * 3UL
1081
+ return sizeForLength + sizeForString
1082
+ }
1083
+
1084
+ override fun write(value: String, buf: ByteBuffer) {
1085
+ val byteBuf = toUtf8(value)
1086
+ buf.putInt(byteBuf.limit())
1087
+ buf.put(byteBuf)
1088
+ }
1089
+ }
1090
+
1091
+
1092
+
1093
+ data class HighlightRange (
1094
+ var `start`: kotlin.UInt,
1095
+ var `length`: kotlin.UInt,
1096
+ var `color`: kotlin.UInt,
1097
+ var `fontStyle`: kotlin.UByte
1098
+ ) {
1099
+
1100
+ companion object
1101
+ }
1102
+
1103
+ /**
1104
+ * @suppress
1105
+ */
1106
+ public object FfiConverterTypeHighlightRange: FfiConverterRustBuffer<HighlightRange> {
1107
+ override fun read(buf: ByteBuffer): HighlightRange {
1108
+ return HighlightRange(
1109
+ FfiConverterUInt.read(buf),
1110
+ FfiConverterUInt.read(buf),
1111
+ FfiConverterUInt.read(buf),
1112
+ FfiConverterUByte.read(buf),
1113
+ )
1114
+ }
1115
+
1116
+ override fun allocationSize(value: HighlightRange) = (
1117
+ FfiConverterUInt.allocationSize(value.`start`) +
1118
+ FfiConverterUInt.allocationSize(value.`length`) +
1119
+ FfiConverterUInt.allocationSize(value.`color`) +
1120
+ FfiConverterUByte.allocationSize(value.`fontStyle`)
1121
+ )
1122
+
1123
+ override fun write(value: HighlightRange, buf: ByteBuffer) {
1124
+ FfiConverterUInt.write(value.`start`, buf)
1125
+ FfiConverterUInt.write(value.`length`, buf)
1126
+ FfiConverterUInt.write(value.`color`, buf)
1127
+ FfiConverterUByte.write(value.`fontStyle`, buf)
1128
+ }
1129
+ }
1130
+
1131
+
1132
+
1133
+
1134
+
1135
+ sealed class HighlightException: kotlin.Exception() {
1136
+
1137
+ class UnknownTheme(
1138
+
1139
+ val `theme`: kotlin.String
1140
+ ) : HighlightException() {
1141
+ override val message
1142
+ get() = "theme=${ `theme` }"
1143
+ }
1144
+
1145
+
1146
+ companion object ErrorHandler : UniffiRustCallStatusErrorHandler<HighlightException> {
1147
+ override fun lift(error_buf: RustBuffer.ByValue): HighlightException = FfiConverterTypeHighlightError.lift(error_buf)
1148
+ }
1149
+
1150
+
1151
+ }
1152
+
1153
+ /**
1154
+ * @suppress
1155
+ */
1156
+ public object FfiConverterTypeHighlightError : FfiConverterRustBuffer<HighlightException> {
1157
+ override fun read(buf: ByteBuffer): HighlightException {
1158
+
1159
+
1160
+ return when(buf.getInt()) {
1161
+ 1 -> HighlightException.UnknownTheme(
1162
+ FfiConverterString.read(buf),
1163
+ )
1164
+ else -> throw RuntimeException("invalid error enum value, something is very wrong!!")
1165
+ }
1166
+ }
1167
+
1168
+ override fun allocationSize(value: HighlightException): ULong {
1169
+ return when(value) {
1170
+ is HighlightException.UnknownTheme -> (
1171
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1172
+ 4UL
1173
+ + FfiConverterString.allocationSize(value.`theme`)
1174
+ )
1175
+ }
1176
+ }
1177
+
1178
+ override fun write(value: HighlightException, buf: ByteBuffer) {
1179
+ when(value) {
1180
+ is HighlightException.UnknownTheme -> {
1181
+ buf.putInt(1)
1182
+ FfiConverterString.write(value.`theme`, buf)
1183
+ Unit
1184
+ }
1185
+ }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
1186
+ }
1187
+
1188
+ }
1189
+
1190
+
1191
+
1192
+
1193
+ /**
1194
+ * @suppress
1195
+ */
1196
+ public object FfiConverterOptionalString: FfiConverterRustBuffer<kotlin.String?> {
1197
+ override fun read(buf: ByteBuffer): kotlin.String? {
1198
+ if (buf.get().toInt() == 0) {
1199
+ return null
1200
+ }
1201
+ return FfiConverterString.read(buf)
1202
+ }
1203
+
1204
+ override fun allocationSize(value: kotlin.String?): ULong {
1205
+ if (value == null) {
1206
+ return 1UL
1207
+ } else {
1208
+ return 1UL + FfiConverterString.allocationSize(value)
1209
+ }
1210
+ }
1211
+
1212
+ override fun write(value: kotlin.String?, buf: ByteBuffer) {
1213
+ if (value == null) {
1214
+ buf.put(0)
1215
+ } else {
1216
+ buf.put(1)
1217
+ FfiConverterString.write(value, buf)
1218
+ }
1219
+ }
1220
+ }
1221
+
1222
+
1223
+
1224
+
1225
+ /**
1226
+ * @suppress
1227
+ */
1228
+ public object FfiConverterSequenceTypeHighlightRange: FfiConverterRustBuffer<List<HighlightRange>> {
1229
+ override fun read(buf: ByteBuffer): List<HighlightRange> {
1230
+ val len = buf.getInt()
1231
+ return List<HighlightRange>(len) {
1232
+ FfiConverterTypeHighlightRange.read(buf)
1233
+ }
1234
+ }
1235
+
1236
+ override fun allocationSize(value: List<HighlightRange>): ULong {
1237
+ val sizeForLength = 4UL
1238
+ val sizeForItems = value.map { FfiConverterTypeHighlightRange.allocationSize(it) }.sum()
1239
+ return sizeForLength + sizeForItems
1240
+ }
1241
+
1242
+ override fun write(value: List<HighlightRange>, buf: ByteBuffer) {
1243
+ buf.putInt(value.size)
1244
+ value.iterator().forEach {
1245
+ FfiConverterTypeHighlightRange.write(it, buf)
1246
+ }
1247
+ }
1248
+ }
1249
+ @Throws(HighlightException::class) fun `highlightCode`(`text`: kotlin.String, `language`: kotlin.String?, `theme`: kotlin.String): List<HighlightRange> {
1250
+ return FfiConverterSequenceTypeHighlightRange.lift(
1251
+ uniffiRustCallWithError(HighlightException) { _status ->
1252
+ UniffiLib.INSTANCE.uniffi_native_editor_highlighting_fn_func_highlight_code(
1253
+ FfiConverterString.lower(`text`),FfiConverterOptionalString.lower(`language`),FfiConverterString.lower(`theme`),_status)
1254
+ }
1255
+ )
1256
+ }
1257
+
1258
+
1259
+