mirror of
https://github.com/pointfreeco/swift-custom-dump.git
synced 2026-04-07 19:17:35 +00:00
27 lines
744 B
Swift
27 lines
744 B
Swift
/// A type that can be converted to a value for the purpose of dumping.
|
|
///
|
|
/// The `CustomDumpRepresentable` protocol allows you to return _any_ value for the purpose of
|
|
/// dumping. This can be used to flatten the dump representation of wrapper types. For example, a
|
|
/// type-safe identifier may want to dump its raw value directly:
|
|
///
|
|
/// ```swift
|
|
/// struct ID: RawRepresentable {
|
|
/// var rawValue: String
|
|
/// }
|
|
///
|
|
/// extension ID: CustomDumpRepresentable {
|
|
/// var customDumpValue: Any {
|
|
/// rawValue
|
|
/// }
|
|
/// }
|
|
///
|
|
/// customDump(ID(rawValue: "deadbeef")
|
|
/// ```
|
|
/// ```text
|
|
/// "deadbeef"
|
|
/// ```
|
|
public protocol CustomDumpRepresentable {
|
|
/// The custom dump value for this instance.
|
|
var customDumpValue: Any { get }
|
|
}
|