xref: /aosp_15_r20/external/kotlinx.atomicfu/atomicfu/src/commonMain/kotlin/kotlinx/atomicfu/TraceFormat.kt (revision 68017707106cb9da9fed635c150bc497c09c160f)
1 /*
2  * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
6 
7 package kotlinx.atomicfu
8 
9 import kotlin.internal.InlineOnly
10 import kotlin.js.JsName
11 
12 /**
13  * Trace string formatter.
14  */
15 @OptionalJsName(TRACE_FORMAT_CLASS)
16 public open class TraceFormat {
17     /**
18      * Formats trace at the given [index] with the given [event] of Any type.
19      */
20     @OptionalJsName(TRACE_FORMAT_FORMAT_FUNCTION)
formatnull21     public open fun format(index: Int, event: Any): String = "$index: $event"
22 }
23 
24 /**
25  * Creates trace string formatter with the given [format] code block.
26  */
27 @InlineOnly
28 public inline fun TraceFormat(crossinline format: (index: Int, event: Any) -> String): TraceFormat =
29     object : TraceFormat() {
30         override fun format(index: Int, event: Any): String = format(index, event)
31     }