More access to HandleWrapper members because it anyway must be wrapped

This commit is contained in:
Andrew Golovashevich 2025-09-05 00:49:19 +03:00
parent bdb1fe56fa
commit 4b799c0ecf
2 changed files with 7 additions and 9 deletions

View File

@ -15,7 +15,7 @@ buildscript {
}
group = "ru.landgrafhomyak.utility"
version = "1.1"
version = "1.2"
repositories {
mavenCentral()

View File

@ -4,24 +4,22 @@ import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
public class HandleWrapper<H>(
handle: H,
state: CloseableState,
public val handle: H,
public val state: CloseableState,
) {
private val _unprotected = handle
private val _state: CloseableState = state
public fun <R> useHandle(method: (H) -> R): R {
contract {
callsInPlace(method, InvocationKind.EXACTLY_ONCE)
}
return this._state.withUse { method(this._unprotected) }
return this.state.withUse { method(this.handle) }
}
@ManualStateManipulation
private fun close() {
this._state.close()
public fun close() {
this.state.close()
}
override fun toString(): String = "<wrapper of handle=${this._unprotected} protected with state=${this._state}>"
override fun toString(): String = "<wrapper of handle=${this.handle} protected with state=${this.state}>"
}