-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathCustomDumpStringConvertible.swift
66 lines (66 loc) · 1.97 KB
/
CustomDumpStringConvertible.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/// A type with a customized textual representation for ``customDump(_:to:name:indent:maxDepth:)``
/// and ``diff(_:_:format:)``.
///
/// Types that want to customize their dump output can conform to this protocol. It is most
/// appropriate for types that have a simple, un-nested internal representation, and typically its
/// output fits on a single line, for example dates, UUIDs, URLs, etc.
///
/// For data types with more structure, for example those with nesting and multiple fields, see the
/// ``CustomDumpReflectable`` protocol.
///
/// The library conforms a bunch of Foundation types to this protocol to simplify their dump output:
///
/// ```swift
/// extension URL: CustomDumpStringConvertible {
/// public var customDumpDescription: String {
/// "URL(\(self.absoluteString))"
/// }
/// }
///
/// customDump(URL(string: "https://www.pointfree.co/")!)
/// ```
/// ```text
/// URL(https://www.pointfree.co/)
/// ```
///
/// Custom Dump also uses this protocol internally to provide more useful output for enums imported
/// from Objective-C:
///
/// ```swift
/// import UserNotifications
///
/// print("dump:")
/// dump(UNNotificationSetting.disabled)
/// print("customDump:")
/// customDump(UNNotificationSetting.disabled)
/// ```
/// ```text
/// dump:
/// - __C.UNNotificationSetting
/// customDump:
/// UNNotificationSettings.disabled
/// ```
///
/// Any time you want to override the dump representation with some other string, you can use this
/// protocol.
///
/// For example, you could introduce a wrapper type that "redacts" a portion of a dump:
///
/// ```swift
/// struct Redacted<RawValue>: CustomDumpStringConvertible {
/// let rawValue: RawValue
///
/// var customDumpDescription: String {
/// "<redacted>"
/// }
/// }
///
/// customDump(Redacted(rawValue: "my super secret password"))
/// ```
/// ```text
/// <redacted>
/// ```
public protocol CustomDumpStringConvertible {
/// The custom dump description for this instance.
var customDumpDescription: String { get }
}