silk/standard_streams
Complete-message standard-output and standard-error writes through a replaceable service.
When to use
Use StandardStreams for complete byte messages to stdout or stderr; structured logging
belongs in silk.logger.
Details
StandardStreams is an ordinary source-declared service. Its requirement remains in an
Effect until a caller supplies a provider, so tests and applications can replace the
process-backed implementation lexically. Stream failure is typed as StreamWriteError.
Examples
Write one complete standard-output message
import silk.effect { Effect }
import silk.standard_streams { StandardStreams }
effect fn writeMessage() -> ()
! StandardStreams.StreamWriteError {
let mut streams = StandardStreams.nativeStandardStreamProvider()
return run StandardStreams.send(StandardStreams.stdout(), b"Silk\n")
|> Effect.provideMut<StandardStreams>(&mut streams)
}
effect fn ignoreWriteFailure(error: StandardStreams.StreamWriteError) -> () {
return ()
}
pub fn main() -> i32 {
let completed = run Effect.catchAll(writeMessage(), ignoreWriteFailure)
return 42
}Import as StandardStreams with import silk.standard_streams.
Public declarations: 7.
StreamWriteError
pub struct StreamWriteErrorA failure to commit one complete standard-stream message.
StandardStreams
pub service StandardStreamsA mutable service that writes complete messages to standard output or standard error.
Operation writeAll
effect fn writeAll(destination: bool, bytes: &[u8]) -> () ! StreamWriteError ? &mut StandardStreamsWrites a complete immutable byte sequence to the selected standard-stream destination.
Gotchas
A failure means that the service did not commit the complete message.
NativeStandardStreams
pub struct NativeStandardStreamsA process-backed provider for StandardStreams.
stdout
pub fn stdout() -> boolReturns the destination value that selects process standard output.
stderr
pub fn stderr() -> boolReturns the destination value that selects process standard error.
nativeStandardStreamProvider
pub fn nativeStandardStreamProvider() -> NativeStandardStreamsCreates a process-backed standard-stream provider.
Implementation StandardStreams for NativeStandardStreams
impl StandardStreams for NativeStandardStreamsOperation writeAll
writeAll = NativeStandardStreams.nativeWriteAllsend
pub effect fn send(destination: bool, bytes: &[u8]) -> () ! StreamWriteError ? &mut StandardStreamsWrites one complete immutable byte sequence to a selected standard stream.
Details
The returned Effect requires a mutable StandardStreams provider. Use stdout or
stderr for destination.