Skip to content

Commit 2a4e916

Browse files
committed
Rename OutputStream to TextOutputStream [SE-0086]
1 parent e25c751 commit 2a4e916

12 files changed

+78
-78
lines changed

docs/StringDesign.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ Building
993993
.. sidebar:: ``append``
994994

995995
the ``append`` method is a consequence of ``String``\ 's
996-
conformance to ``OutputStream``. See the *Swift
996+
conformance to ``TextOutputStream``. See the *Swift
997997
formatting proposal* for details.
998998

999999
:Swift:

docs/TextFormatting.rst

+27-27
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,18 @@ Design Details
109109
Output Streams
110110
..............
111111

112-
The most fundamental part of this design is ``OutputStream``, a thing
112+
The most fundamental part of this design is ``TextOutputStream``, a thing
113113
into which we can stream text: [#character1]_
114114

115115
::
116116

117-
protocol OutputStream {
117+
protocol TextOutputStream {
118118
func append(_ text: String)
119119
}
120120

121-
Every ``String`` can be used as an ``OutputStream`` directly::
121+
Every ``String`` can be used as an ``TextOutputStream`` directly::
122122

123-
extension String : OutputStream {
123+
extension String : TextOutputStream {
124124
func append(_ text: String)
125125
}
126126

@@ -142,7 +142,7 @@ need to declare conformance: simply give the type a ``debugFormat()``::
142142

143143
Because ``String`` is a ``Streamable``, your implementation of
144144
``debugFormat`` can just return a ``String``. If want to write
145-
directly to the ``OutputStream`` for efficiency reasons,
145+
directly to the ``TextOutputStream`` for efficiency reasons,
146146
(e.g. if your representation is huge), you can return a custom
147147
``DebugRepresentation`` type.
148148

@@ -197,11 +197,11 @@ implement::
197197
Because it's not always efficient to construct a ``String``
198198
representation before writing an object to a stream, we provide a
199199
``Streamable`` protocol, for types that can write themselves into an
200-
``OutputStream``. Every ``Streamable`` is also a ``CustomStringConvertible``,
200+
``TextOutputStream``. Every ``Streamable`` is also a ``CustomStringConvertible``,
201201
naturally::
202202

203203
protocol Streamable : CustomStringConvertible {
204-
func writeTo<T: OutputStream>(_ target: [inout] T)
204+
func writeTo<T: TextOutputStream>(_ target: [inout] T)
205205

206206
// You'll never want to reimplement this
207207
func format() -> PrintRepresentation {
@@ -224,7 +224,7 @@ adds surrounding quotes and escapes special characters::
224224
struct EscapedStringRepresentation : Streamable {
225225
var _value: String
226226

227-
func writeTo<T: OutputStream>(_ target: [inout] T) {
227+
func writeTo<T: TextOutputStream>(_ target: [inout] T) {
228228
target.append("\"")
229229
for c in _value {
230230
target.append(c.escape())
@@ -233,11 +233,11 @@ adds surrounding quotes and escapes special characters::
233233
}
234234
}
235235

236-
Besides modeling ``OutputStream``, ``String`` also conforms to
236+
Besides modeling ``TextOutputStream``, ``String`` also conforms to
237237
``Streamable``::
238238

239239
extension String : Streamable {
240-
func writeTo<T: OutputStream>(_ target: [inout] T) {
240+
func writeTo<T: TextOutputStream>(_ target: [inout] T) {
241241
target.append(self) // Append yourself to the stream
242242
}
243243

@@ -275,12 +275,12 @@ complicated ``format(…)`` might be written::
275275
struct RadixFormat<T: CustomStringConvertibleInteger> : Streamable {
276276
var value: T, radix = 10, fill = " ", width = 0
277277

278-
func writeTo<S: OutputStream>(_ target: [inout] S) {
278+
func writeTo<S: TextOutputStream>(_ target: [inout] S) {
279279
_writeSigned(value, &target)
280280
}
281281

282282
// Write the given positive value to stream
283-
func _writePositive<T:CustomStringConvertibleInteger, S: OutputStream>(
283+
func _writePositive<T:CustomStringConvertibleInteger, S: TextOutputStream>(
284284
_ value: T, stream: [inout] S
285285
) -> Int {
286286
if value == 0 { return 0 }
@@ -293,7 +293,7 @@ complicated ``format(…)`` might be written::
293293
return nDigits + 1
294294
}
295295

296-
func _writeSigned<T:CustomStringConvertibleInteger, S: OutputStream>(
296+
func _writeSigned<T:CustomStringConvertibleInteger, S: TextOutputStream>(
297297
_ value: T, target: [inout] S
298298
) {
299299
var width = 0
@@ -333,15 +333,15 @@ considerable thought, they are included here for completeness and to
333333
ensure our proposed design doesn't rule out important directions of
334334
evolution.
335335

336-
``OutputStream`` Adapters
336+
``TextOutputStream`` Adapters
337337
.........................
338338

339339
Most text transformations can be expressed as adapters over generic
340-
``OutputStream``\ s. For example, it's easy to imagine an upcasing
340+
``TextOutputStream``\ s. For example, it's easy to imagine an upcasing
341341
adapter that transforms its input to upper case before writing it to
342342
an underlying stream::
343343

344-
struct UpperStream<UnderlyingStream:OutputStream> : OutputStream {
344+
struct UpperStream<UnderlyingStream:TextOutputStream> : TextOutputStream {
345345
func append(_ x: String) { base.append(x.toUpper()) }
346346
var base: UnderlyingStream
347347
}
@@ -353,26 +353,26 @@ processed and written to the underlying stream:
353353

354354
.. parsed-literal::
355355
356-
struct TrimStream<UnderlyingStream:OutputStream> : OutputStream {
356+
struct TrimStream<UnderlyingStream:TextOutputStream> : TextOutputStream {
357357
func append(_ x: String) { ... }
358358
**func close() { ... }**
359359
var base: UnderlyingStream
360360
var bufferedWhitespace: String
361361
}
362362
363-
This makes general ``OutputStream`` adapters more complicated to write
364-
and use than ordinary ``OutputStream``\ s.
363+
This makes general ``TextOutputStream`` adapters more complicated to write
364+
and use than ordinary ``TextOutputStream``\ s.
365365

366366
``Streamable`` Adapters
367367
.......................
368368

369-
For every conceivable ``OutputStream`` adaptor there's a corresponding
369+
For every conceivable ``TextOutputStream`` adaptor there's a corresponding
370370
``Streamable`` adaptor. For example::
371371

372372
struct UpperStreamable<UnderlyingStreamable:Streamable> {
373373
var base: UnderlyingStreamable
374374

375-
func writeTo<T: OutputStream>(_ target: [inout] T) {
375+
func writeTo<T: TextOutputStream>(_ target: [inout] T) {
376376
var adaptedStream = UpperStream(target)
377377
self.base.writeTo(&adaptedStream)
378378
target = adaptedStream.base
@@ -418,20 +418,20 @@ least until we do, we opt not to trade away any CPU, memory, and
418418
power.
419419

420420
If we were willing to say that only ``class``\ es can conform to
421-
``OutputStream``, we could eliminate the explicit ``[inout]`` where
422-
``OutputStream``\ s are passed around. Then, we'd simply need a
421+
``TextOutputStream``, we could eliminate the explicit ``[inout]`` where
422+
``TextOutputStream``\ s are passed around. Then, we'd simply need a
423423
``class StringStream`` for creating ``String`` representations. It
424-
would also make ``OutputStream`` adapters a *bit* simpler to use
424+
would also make ``TextOutputStream`` adapters a *bit* simpler to use
425425
because you'd never need to "write back" explicitly onto the target
426-
stream. However, stateful ``OutputStream`` adapters would still need a
426+
stream. However, stateful ``TextOutputStream`` adapters would still need a
427427
``close()`` method, which makes a perfect place to return a copy of
428428
the underlying stream, which can then be "written back":
429429

430430
.. parsed-literal::
431431
432432
struct AdaptedStreamable<T:Streamable> {
433433
...
434-
func writeTo<Target: OutputStream>(_ target: [inout] Target) {
434+
func writeTo<Target: TextOutputStream>(_ target: [inout] Target) {
435435
// create the stream that transforms the representation
436436
var adaptedTarget = adapt(target, adapter);
437437
// write the Base object to the target stream
@@ -444,7 +444,7 @@ the underlying stream, which can then be "written back":
444444
}
445445
446446
We think anyone writing such adapters can handle the need for explicit
447-
write-back, and the ability to use ``String`` as an ``OutputStream``
447+
write-back, and the ability to use ``String`` as an ``TextOutputStream``
448448
without additionally allocating a ``StringStream`` on the heap seems
449449
to tip the balance in favor of the current design.
450450

stdlib/private/SwiftPrivate/IO.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public struct _FDInputStream {
8181
}
8282
}
8383

84-
public struct _Stderr : OutputStream {
84+
public struct _Stderr : TextOutputStream {
8585
public init() {}
8686

8787
public mutating func write(_ string: String) {
@@ -91,7 +91,7 @@ public struct _Stderr : OutputStream {
9191
}
9292
}
9393

94-
public struct _FDOutputStream : OutputStream {
94+
public struct _FDOutputStream : TextOutputStream {
9595
public let fd: CInt
9696
public var isClosed: Bool = false
9797

stdlib/public/core/DebuggerSupport.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public enum _DebuggerSupport {
158158
}
159159
}
160160

161-
internal static func printForDebuggerImpl<StreamType : OutputStream>(
161+
internal static func printForDebuggerImpl<StreamType : TextOutputStream>(
162162
value: Any?,
163163
mirror: Mirror,
164164
name: String?,

stdlib/public/core/OutputStream.swift

+25-25
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import SwiftShims
2020
///
2121
/// You can send the output of the standard library's `print(_:to:)` and
2222
/// `dump(_:to:)` functions to an instance of a type that conforms to the
23-
/// `OutputStream` protocol instead of to standard output. Swift's `String`
24-
/// type conforms to `OutputStream` already, so you can capture the output
23+
/// `TextOutputStream` protocol instead of to standard output. Swift's `String`
24+
/// type conforms to `TextOutputStream` already, so you can capture the output
2525
/// from `print(_:to:)` and `dump(_:to:)` in a string instead of logging it to
2626
/// standard output.
2727
///
@@ -31,18 +31,18 @@ import SwiftShims
3131
/// }
3232
/// // s == "12345"
3333
///
34-
/// Conforming to the OutputStream Protocol
34+
/// Conforming to the TextOutputStream Protocol
3535
/// =======================================
3636
///
37-
/// To make your custom type conform to the `OutputStream` protocol, implement
38-
/// the required `write(_:)` method. Functions that use an `OutputStream`
37+
/// To make your custom type conform to the `TextOutputStream` protocol, implement
38+
/// the required `write(_:)` method. Functions that use an `TextOutputStream`
3939
/// target may call `write(_:)` multiple times per writing operation.
4040
///
4141
/// As an example, here's an implementation of an output stream that converts
4242
/// any input to its plain ASCII representation before sending it to standard
4343
/// output.
4444
///
45-
/// struct ASCIILogger: OutputStream {
45+
/// struct ASCIILogger: TextOutputStream {
4646
/// mutating func write(_ string: String) {
4747
/// let ascii = string.unicodeScalars.lazy.map { scalar in
4848
/// scalar == "\n"
@@ -65,23 +65,23 @@ import SwiftShims
6565
/// var asciiLogger = ASCIILogger()
6666
/// print(s, to: &asciiLogger)
6767
/// // Prints "Hearts \u{2661} and Diamonds \u{2662}"
68-
public protocol OutputStream {
68+
public protocol TextOutputStream {
6969
mutating func _lock()
7070
mutating func _unlock()
7171

7272
/// Appends the given string to the stream.
7373
mutating func write(_ string: String)
7474
}
7575

76-
extension OutputStream {
76+
extension TextOutputStream {
7777
public mutating func _lock() {}
7878
public mutating func _unlock() {}
7979
}
8080

8181
/// A source of text-streaming operations.
8282
///
8383
/// Instances of types that conform to the `Streamable` protocol can write
84-
/// their value to instances of any type that conforms to the `OutputStream`
84+
/// their value to instances of any type that conforms to the `TextOutputStream`
8585
/// protocol. The Swift standard library's text-related types, `String`,
8686
/// `Character`, and `UnicodeScalar`, all conform to `Streamable`.
8787
///
@@ -94,7 +94,7 @@ extension OutputStream {
9494
public protocol Streamable {
9595
/// Writes a textual representation of this instance into the given output
9696
/// stream.
97-
func write<Target : OutputStream>(to target: inout Target)
97+
func write<Target : TextOutputStream>(to target: inout Target)
9898
}
9999

100100
/// A type with a customized textual representation.
@@ -229,7 +229,7 @@ func _getEnumCaseName<T>(_ value: T) -> UnsafePointer<CChar>?
229229
func _opaqueSummary(_ metadata: Any.Type) -> UnsafePointer<CChar>?
230230

231231
/// Do our best to print a value that cannot be printed directly.
232-
internal func _adHocPrint_unlocked<T, TargetStream : OutputStream>(
232+
internal func _adHocPrint_unlocked<T, TargetStream : TextOutputStream>(
233233
_ value: T, _ mirror: Mirror, _ target: inout TargetStream,
234234
isDebugPrint: Bool
235235
) {
@@ -316,7 +316,7 @@ internal func _adHocPrint_unlocked<T, TargetStream : OutputStream>(
316316

317317
@inline(never)
318318
@_semantics("stdlib_binary_only")
319-
internal func _print_unlocked<T, TargetStream : OutputStream>(
319+
internal func _print_unlocked<T, TargetStream : TextOutputStream>(
320320
_ value: T, _ target: inout TargetStream
321321
) {
322322
// Optional has no representation suitable for display; therefore,
@@ -372,7 +372,7 @@ func _toStringReadOnlyPrintable<T : CustomStringConvertible>(_ x: T) -> String {
372372
//===----------------------------------------------------------------------===//
373373

374374
@inline(never)
375-
public func _debugPrint_unlocked<T, TargetStream : OutputStream>(
375+
public func _debugPrint_unlocked<T, TargetStream : TextOutputStream>(
376376
_ value: T, _ target: inout TargetStream
377377
) {
378378
if let debugPrintableObject = value as? CustomDebugStringConvertible {
@@ -394,7 +394,7 @@ public func _debugPrint_unlocked<T, TargetStream : OutputStream>(
394394
_adHocPrint_unlocked(value, mirror, &target, isDebugPrint: true)
395395
}
396396

397-
internal func _dumpPrint_unlocked<T, TargetStream : OutputStream>(
397+
internal func _dumpPrint_unlocked<T, TargetStream : TextOutputStream>(
398398
_ value: T, _ mirror: Mirror, _ target: inout TargetStream
399399
) {
400400
if let displayStyle = mirror.displayStyle {
@@ -463,7 +463,7 @@ internal func _dumpPrint_unlocked<T, TargetStream : OutputStream>(
463463
// OutputStreams
464464
//===----------------------------------------------------------------------===//
465465

466-
internal struct _Stdout : OutputStream {
466+
internal struct _Stdout : TextOutputStream {
467467
mutating func _lock() {
468468
_swift_stdlib_flockfile_stdout()
469469
}
@@ -489,7 +489,7 @@ internal struct _Stdout : OutputStream {
489489
}
490490
}
491491

492-
extension String : OutputStream {
492+
extension String : TextOutputStream {
493493
/// Appends the given string to this string.
494494
///
495495
/// - Parameter other: A string to append.
@@ -506,7 +506,7 @@ extension String : Streamable {
506506
/// Writes the string into the given output stream.
507507
///
508508
/// - Parameter target: An output stream.
509-
public func write<Target : OutputStream>(to target: inout Target) {
509+
public func write<Target : TextOutputStream>(to target: inout Target) {
510510
target.write(self)
511511
}
512512
}
@@ -515,7 +515,7 @@ extension Character : Streamable {
515515
/// Writes the character into the given output stream.
516516
///
517517
/// - Parameter target: An output stream.
518-
public func write<Target : OutputStream>(to target: inout Target) {
518+
public func write<Target : TextOutputStream>(to target: inout Target) {
519519
target.write(String(self))
520520
}
521521
}
@@ -525,7 +525,7 @@ extension UnicodeScalar : Streamable {
525525
/// output stream.
526526
///
527527
/// - Parameter target: An output stream.
528-
public func write<Target : OutputStream>(to target: inout Target) {
528+
public func write<Target : TextOutputStream>(to target: inout Target) {
529529
target.write(String(Character(self)))
530530
}
531531
}
@@ -534,9 +534,9 @@ extension UnicodeScalar : Streamable {
534534
public var _playgroundPrintHook : ((String) -> Void)? = {_ in () }
535535

536536
internal struct _TeeStream<
537-
L : OutputStream,
538-
R : OutputStream
539-
> : OutputStream {
537+
L : TextOutputStream,
538+
R : TextOutputStream
539+
> : TextOutputStream {
540540
var left: L
541541
var right: R
542542

@@ -548,12 +548,12 @@ internal struct _TeeStream<
548548
mutating func _unlock() { right._unlock(); left._unlock() }
549549
}
550550

551-
@available(*, unavailable, renamed: "OutputStream")
552-
public typealias OutputStreamType = OutputStream
551+
@available(*, unavailable, renamed: "TextOutputStream")
552+
public typealias OutputStreamType = TextOutputStream
553553

554554
extension Streamable {
555555
@available(*, unavailable, renamed: "write(to:)")
556-
public func writeTo<Target : OutputStream>(_ target: inout Target) {
556+
public func writeTo<Target : TextOutputStream>(_ target: inout Target) {
557557
Builtin.unreachable()
558558
}
559559
}

0 commit comments

Comments
 (0)