Skip to content

Commit 185f478

Browse files
authored
Merge pull request #4391 from moiseev/streamable-rename-ccc
[swift-3.0-branch] Renaming Streamable (part of SE-0137)
2 parents 6281861 + c91be8e commit 185f478

File tree

5 files changed

+35
-30
lines changed

5 files changed

+35
-30
lines changed

stdlib/public/core/Mirror.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ extension String {
838838
/// string representation of `instance` in one of the following ways,
839839
/// depending on its protocol conformance:
840840
///
841-
/// - If `instance` conforms to the `Streamable` protocol, the result is
841+
/// - If `instance` conforms to the `TextOutputStreamable` protocol, the result is
842842
/// obtained by calling `instance.write(to: s)` on an empty string `s`.
843843
/// - If `instance` conforms to the `CustomStringConvertible` protocol, the
844844
/// result is `instance.description`.
@@ -888,7 +888,7 @@ extension String {
888888
/// the result is `subject.debugDescription`.
889889
/// - If `subject` conforms to the `CustomStringConvertible` protocol, the
890890
/// result is `subject.description`.
891-
/// - If `subject` conforms to the `Streamable` protocol, the result is
891+
/// - If `subject` conforms to the `TextOutputStreamable` protocol, the result is
892892
/// obtained by calling `subject.write(to: s)` on an empty string `s`.
893893
/// - An unspecified result is supplied automatically by the Swift standard
894894
/// library.

stdlib/public/core/OutputStream.swift

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,27 @@ extension TextOutputStream {
8181

8282
/// A source of text-streaming operations.
8383
///
84-
/// Instances of types that conform to the `Streamable` protocol can write
85-
/// their value to instances of any type that conforms to the `TextOutputStream`
86-
/// protocol. The Swift standard library's text-related types, `String`,
87-
/// `Character`, and `UnicodeScalar`, all conform to `Streamable`.
84+
/// Instances of types that conform to the `TextOutputStreamable` protocol can
85+
/// write their value to instances of any type that conforms to the
86+
/// `TextOutputStream` protocol. The Swift standard library's text-related
87+
/// types, `String`, `Character`, and `UnicodeScalar`, all conform to
88+
/// `TextOutputStreamable`.
8889
///
89-
/// Conforming to the Streamable Protocol
90+
/// Conforming to the TextOutputStreamable Protocol
9091
/// =====================================
9192
///
92-
/// To add `Streamable` conformance to a custom type, implement the required
93-
/// `write(to:)` method. Call the given output stream's `write(_:)` method in
94-
/// your implementation.
95-
public protocol Streamable {
93+
/// To add `TextOutputStreamable` conformance to a custom type, implement the
94+
/// required `write(to:)` method. Call the given output stream's `write(_:)`
95+
/// method in your implementation.
96+
public protocol TextOutputStreamable {
9697
/// Writes a textual representation of this instance into the given output
9798
/// stream.
9899
func write<Target : TextOutputStream>(to target: inout Target)
99100
}
100101

102+
// @available(*, unavailable, renamed: "TextOutputStreamable")
103+
public typealias Streamable = TextOutputStreamable
104+
101105
/// A type with a customized textual representation.
102106
///
103107
/// Types that conform to the `CustomStringConvertible` protocol can provide
@@ -346,7 +350,7 @@ internal func _print_unlocked<T, TargetStream : TextOutputStream>(
346350
debugPrintable.debugDescription.write(to: &target)
347351
return
348352
}
349-
if case let streamableObject as Streamable = value {
353+
if case let streamableObject as TextOutputStreamable = value {
350354
streamableObject.write(to: &target)
351355
return
352356
}
@@ -373,7 +377,7 @@ internal func _print_unlocked<T, TargetStream : TextOutputStream>(
373377
/// This function is forbidden from being inlined because when building the
374378
/// standard library inlining makes us drop the special semantics.
375379
@inline(never) @effects(readonly)
376-
func _toStringReadOnlyStreamable<T : Streamable>(_ x: T) -> String {
380+
func _toStringReadOnlyStreamable<T : TextOutputStreamable>(_ x: T) -> String {
377381
var result = ""
378382
x.write(to: &result)
379383
return result
@@ -402,7 +406,7 @@ public func _debugPrint_unlocked<T, TargetStream : TextOutputStream>(
402406
return
403407
}
404408

405-
if let streamableObject = value as? Streamable {
409+
if let streamableObject = value as? TextOutputStreamable {
406410
streamableObject.write(to: &target)
407411
return
408412
}
@@ -415,7 +419,8 @@ internal func _dumpPrint_unlocked<T, TargetStream : TextOutputStream>(
415419
_ value: T, _ mirror: Mirror, _ target: inout TargetStream
416420
) {
417421
if let displayStyle = mirror.displayStyle {
418-
// Containers and tuples are always displayed in terms of their element count
422+
// Containers and tuples are always displayed in terms of their element
423+
// count
419424
switch displayStyle {
420425
case .tuple:
421426
let count = mirror.children.count
@@ -448,7 +453,7 @@ internal func _dumpPrint_unlocked<T, TargetStream : TextOutputStream>(
448453
return
449454
}
450455

451-
if let streamableObject = value as? Streamable {
456+
if let streamableObject = value as? TextOutputStreamable {
452457
streamableObject.write(to: &target)
453458
return
454459
}
@@ -519,7 +524,7 @@ extension String : TextOutputStream {
519524
// Streamables
520525
//===----------------------------------------------------------------------===//
521526

522-
extension String : Streamable {
527+
extension String : TextOutputStreamable {
523528
/// Writes the string into the given output stream.
524529
///
525530
/// - Parameter target: An output stream.
@@ -528,7 +533,7 @@ extension String : Streamable {
528533
}
529534
}
530535

531-
extension Character : Streamable {
536+
extension Character : TextOutputStreamable {
532537
/// Writes the character into the given output stream.
533538
///
534539
/// - Parameter target: An output stream.
@@ -537,7 +542,7 @@ extension Character : Streamable {
537542
}
538543
}
539544

540-
extension UnicodeScalar : Streamable {
545+
extension UnicodeScalar : TextOutputStreamable {
541546
/// Writes the textual representation of the Unicode scalar into the given
542547
/// output stream.
543548
///
@@ -568,7 +573,7 @@ internal struct _TeeStream<
568573
@available(*, unavailable, renamed: "TextOutputStream")
569574
public typealias OutputStreamType = TextOutputStream
570575

571-
extension Streamable {
576+
extension TextOutputStreamable {
572577
@available(*, unavailable, renamed: "write(to:)")
573578
public func writeTo<Target : TextOutputStream>(_ target: inout Target) {
574579
Builtin.unreachable()

stdlib/public/core/Print.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
/// - terminator: The string to print after all items have been printed. The
5151
/// default is a newline (`"\n"`).
5252
///
53-
/// - SeeAlso: `debugPrint(_:separator:terminator:)`, `Streamable`,
53+
/// - SeeAlso: `debugPrint(_:separator:terminator:)`, `TextOutputStreamable`,
5454
/// `CustomStringConvertible`, `CustomDebugStringConvertible`
5555
@inline(never)
5656
@_semantics("stdlib_binary_only")
@@ -113,7 +113,7 @@ public func print(
113113
/// - terminator: The string to print after all items have been printed. The
114114
/// default is a newline (`"\n"`).
115115
///
116-
/// - SeeAlso: `print(_:separator:terminator:)`, `Streamable`,
116+
/// - SeeAlso: `print(_:separator:terminator:)`, `TextOutputStreamable`,
117117
/// `CustomStringConvertible`, `CustomDebugStringConvertible`
118118
@inline(never)
119119
@_semantics("stdlib_binary_only")
@@ -174,7 +174,7 @@ public func debugPrint(
174174
///
175175
/// - SeeAlso: `print(_:separator:terminator:)`,
176176
/// `debugPrint(_:separator:terminator:to:)`, `TextOutputStream`,
177-
/// `Streamable`, `CustomStringConvertible`, `CustomDebugStringConvertible`
177+
/// `TextOutputStreamable`, `CustomStringConvertible`, `CustomDebugStringConvertible`
178178
@inline(__always)
179179
public func print<Target : TextOutputStream>(
180180
_ items: Any...,
@@ -225,7 +225,7 @@ public func print<Target : TextOutputStream>(
225225
/// item.
226226
///
227227
/// - SeeAlso: `debugPrint(_:separator:terminator:)`,
228-
/// `print(_:separator:terminator:to:)`, `TextOutputStream`, `Streamable`,
228+
/// `print(_:separator:terminator:to:)`, `TextOutputStream`, `TextOutputStreamable`,
229229
/// `CustomStringConvertible`, `CustomDebugStringConvertible`
230230
@inline(__always)
231231
public func debugPrint<Target : TextOutputStream>(

test/1_stdlib/Optional.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class TestString : CustomStringConvertible, CustomDebugStringConvertible {
351351
return "XString"
352352
}
353353
}
354-
class TestStream : Streamable {
354+
class TestStream : TextOutputStreamable {
355355
func write<Target : TextOutputStream>(to target: inout Target) {
356356
target.write("AStream")
357357
}
@@ -371,8 +371,8 @@ OptionalTests.test("Optional TextOutputStream") {
371371
let optNoString: TestNoString? = TestNoString()
372372
expectFalse(optNoString is CustomStringConvertible)
373373
expectFalse(canGenericCast(optNoString, CustomStringConvertible.self))
374-
expectFalse(optNoString is Streamable)
375-
expectFalse(canGenericCast(optNoString, Streamable.self))
374+
expectFalse(optNoString is TextOutputStreamable)
375+
expectFalse(canGenericCast(optNoString, TextOutputStreamable.self))
376376
expectTrue(optNoString is CustomDebugStringConvertible)
377377
expectTrue(canGenericCast(optNoString, CustomDebugStringConvertible.self))
378378
expectEqual(String(describing: optNoString), "Optional(main.TestNoString)")
@@ -388,8 +388,8 @@ OptionalTests.test("Optional TextOutputStream") {
388388
expectEqual(debugPrintStr(optString), "Optional(XString)")
389389

390390
let optStream: TestStream? = TestStream()
391-
expectTrue(optStream is Streamable)
392-
expectTrue(canGenericCast(optStream, Streamable.self))
391+
expectTrue(optStream is TextOutputStreamable)
392+
expectTrue(canGenericCast(optStream, TextOutputStreamable.self))
393393
expectTrue(optStream is CustomDebugStringConvertible)
394394
expectTrue(canGenericCast(optStream, CustomDebugStringConvertible.self))
395395
expectEqual(String(describing: TestStream()), "AStream")

test/1_stdlib/Renames.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func _Optional<T>(x: T) {
355355
func _TextOutputStream() {
356356
func fn<S : OutputStreamType>(_: S) {} // expected-error {{'OutputStreamType' has been renamed to 'TextOutputStream'}} {{15-31=TextOutputStream}} {{none}}
357357
}
358-
func _TextOutputStream<S : Streamable, O : TextOutputStream>(s: S, o: O) {
358+
func _TextOutputStream<S : TextOutputStreamable, O : TextOutputStream>(s: S, o: O) {
359359
var o = o
360360
s.writeTo(&o) // expected-error {{'writeTo' has been renamed to 'write(to:)'}} {{5-12=write}} {{13-13=to: }} {{none}}
361361
}

0 commit comments

Comments
 (0)