|
1 | 1 |
|
2 | | -@attached(extension, conformances: StateModifyingType, names: named(Modifying), named(modify(source:modifier:)), named(ModifyingTarget)) |
3 | | -public macro Writing() = #externalMacro(module: "StructTransactionMacros", type: "WriterMacro") |
| 2 | +@attached(extension, conformances: DetectingType, names: named(Modifying), named(modify(source:modifier:)), named(read(source:reader:)), named(ModifyingTarget)) |
| 3 | +public macro Detecting() = #externalMacro(module: "StructTransactionMacros", type: "WriterMacro") |
4 | 4 |
|
5 | | -public protocol StateModifyingType { |
| 5 | +public protocol DetectingType { |
6 | 6 |
|
7 | 7 | associatedtype Modifying |
8 | 8 |
|
9 | 9 | @discardableResult |
10 | 10 | static func modify(source: inout Self, modifier: (inout Modifying) throws -> Void) rethrows -> ModifyingResult |
| 11 | + |
| 12 | + @discardableResult |
| 13 | + static func read(source: Self, reader: (Modifying) throws -> Void) rethrows -> ReadResult |
11 | 14 | } |
12 | 15 |
|
13 | | -extension StateModifyingType { |
| 16 | +extension DetectingType { |
14 | 17 |
|
15 | 18 | @discardableResult |
16 | 19 | public mutating func modify(modifier: (inout Modifying) throws -> Void) rethrows -> ModifyingResult { |
17 | 20 | try Self.modify(source: &self, modifier: modifier) |
18 | 21 | } |
19 | 22 |
|
| 23 | + @discardableResult |
| 24 | + public mutating func read(reader: (Modifying) throws -> Void) rethrows -> ReadResult { |
| 25 | + try Self.read(source: self, reader: reader) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +public struct ReadResult { |
| 30 | + |
| 31 | + public let readIdentifiers: Set<String> |
| 32 | + |
| 33 | + public init( |
| 34 | + readIdentifiers: Set<String> |
| 35 | + ) { |
| 36 | + self.readIdentifiers = readIdentifiers |
| 37 | + } |
20 | 38 | } |
21 | 39 |
|
| 40 | + |
22 | 41 | public struct ModifyingResult { |
23 | 42 |
|
24 | 43 | public let readIdentifiers: Set<String> |
|
0 commit comments