A (very dirty) configuration example of Project Panama.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

automatic resource mgmt example

bpavuk cb178464 644ebdfb

+10
+10
app/src/main/kotlin/App.kt
··· 3 3 import org.example.interop.ExternStruct 4 4 import org.example.interop.RustApi 5 5 import org.example.interop.jvm_interop_h 6 + import java.lang.foreign.Arena 6 7 7 8 // if IDEA or Kotlin LSP is scared, run ./gradlew :interop-panama:generateJextractBindings. 8 9 // jvm_interop_h is a jextract-generated class. ··· 17 18 val yFromRust = ExternStruct.y(struct) 18 19 println("Rust owns these. x: $xFromRust, y: $yFromRust. also, xy = nice!") 19 20 jvm_interop_h.extern_struct_free(struct) // remember to clean after yourself! 21 + 22 + // or we can rely on automatic scope-based resource management 23 + val arena = Arena.ofConfined() 24 + arena.use { arena -> 25 + val struct2 = ExternStruct.allocate(arena) 26 + ExternStruct.x(struct2, 1234) 27 + ExternStruct.y(struct2, 103) 28 + println("${ExternStruct.x(struct2) + ExternStruct.y(struct2)} using automated cleanup") 29 + } 20 30 }