Enum with contents

val user: LiveData<Result> = liveData {
    emit(Result.loading())
    try {
        emit(Result.success(fetchUser()))
    } catch(ioException: Exception) {
        emit(Result.error(ioException))
    }
}

The class Result looks similar to a struct enum in Rust where the success variant can carry a User while the loading variant does not.

I’m fairly new to Kotlin and I wonder how that class would be defined.

The code is from here but that page is not about the Result class.

See documentation about sealed classes.