SafeWrapper

interface SafeWrapper<T>(source)

A wrapper interface that provides safe and unsafe access to a target object. Safe methods wrap operations in Result to catch and handle exceptions, while unsafe methods execute directly and may throw exceptions.

Type Parameters

T

The type of the wrapped target object

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class Default<T>(t: T) : SafeWrapper<T>

Default implementation of SafeWrapper that wraps a provided target.

Functions

Link copied to clipboard
open fun <R> safe(block: T.() -> R): Result<R>

Executes a synchronous block on the target, catching any exceptions and returning a Result.

Link copied to clipboard
open suspend fun <R> safeS(block: suspend T.() -> R): Result<R>

Executes a suspending block on the target, catching any exceptions (except kotlinx.coroutines.CancellationException) and returning a Result.

Link copied to clipboard
open fun <R> unsafe(block: T.() -> R): R

Executes a synchronous block on the target without exception handling.

Link copied to clipboard
open suspend fun <R> unsafeS(block: suspend T.() -> R): R

Executes a suspending block on the target without exception handling.

Link copied to clipboard
abstract fun unsafeTarget(): T

Provides access to the underlying wrapped target object.