[swift-evolution] Addition of a standardError OutputStream

Xiaodi Wu xiaodi.wu at gmail.com
Mon Jul 11 14:52:22 CDT 2016


You're right. It's at least tricky, if not currently impossible. I take it
back then.

I'd be happy with a `StandardStream` type (though I'd advocate, in the
spirit of Swiftiness, to have it spelled out), with static `output` and
`error`. This might be one of those rare cases where a reference type might
be most appropriate, though, with perhaps a singleton design?

On Mon, Jul 11, 2016 at 2:30 PM, Erica Sadun <erica at ericasadun.com> wrote:

>
> On Jul 11, 2016, at 1:29 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
> Why not just OutputStream.stderr?
>
>
> Can you do an extension like that with state for a protocol?
>
> -- E
>
>
>
> On Mon, Jul 11, 2016 at 14:25 Erica Sadun via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> Just throwing this here. Unfortunately `Stream` is already taken (and
>> tied to Foundation).
>>
>> public struct StdStream {
>>     public struct StderrStream: OutputStream {
>>         public func write(_ string: String) { fputs(string, Darwin.stderr)
>> }
>>     }
>>
>>     public struct StdoutStream: OutputStream {
>>         public func write(_ string: String) { fputs(string, Darwin.stdout)
>> }
>>     }
>>
>>     public static var err = StderrStream()
>>     public static var out = StdoutStream()
>> }
>>
>> So in use, it would look something like
>>
>> str.write(to: &StdStream.out)
>> str.write(to: &StdStream.err)
>>
>> I also considered DarwinStream (seemed too on the nose), UnixStream,
>> Streamfd, BSDStream, etc. Didn't like any of them.
>>
>> -- E, have paintbrush will bikeshed
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160711/a0e1b1e8/attachment.html>


More information about the swift-evolution mailing list