Commit 0aadfb0
committed
[stdlib] Add
As [discussed on the forum][forum], we'll likely want to use
`Duration` as the primary associated type on `protocol Clock`;
however, that protocol currently only has `Instant`.
[forum]: https://forums.swift.org/t/pitch-primary-associated-types-in-the-standard-library/56426/39
To support declaring it as the primary associated type,
`protocol Clock` needs to have `Duration` as an associated type
requirement:
```
@available(SwiftStdlib 5.7, *)
public protocol Clock: Sendable {
associatedtype Duration: DurationProtocol
associatedtype Instant: InstantProtocol where Instant.Duration == Duration
var now: Instant { get }
var minimumResolution: Instant.Duration { get }
func sleep(until deadline: Instant, tolerance: Instant.Duration?) async throws
}
```
This setup is reminiscent of `Sequence.Element` vs.
`Sequence.Iterator.Element`.
SE-0329 has not yet shipped in an ABI stable release, so we still have
the opportunity to address this.
rdar://91591545Clock.Duration as an associated type requirement1 parent 87155f9 commit 0aadfb0
1 file changed
+2
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
0 commit comments