6.65. kink/io/OUTPUT_PRINTER

Provides a `printer` implementation which wraps `output`.

6.65.1. OUTPUT_PRINTER.new(Output Charset Newline ...[$config={}])

`new` makes a val which supports both `printer` and `output` types, which encodes strings using `Charset`, and writes bytes to `Output`.

Config methods:

• C.flush_on_print

• C.replace_conversion_error

• C.synchronize

If C.flush_on_print is called, the buffer of `Output` is flushed every time after `print` or `print_line` is called.

print_xxx methods converts strings into bytes using `Charset`. When a string cannot be encoded, by default, print_xxx methods tail-call $error with an `exception`. If C.replace_conversion_error is called, print_xxx methods write replacement byte sequence at the place of the conversion error.

If C.synchronize is called, access to `Output`, and conversion from str to bin, are serialized by a single mutex. The option is useful when parallel write/print operations are not avoidable, like in the case of stderr.

Preconditions

`Output` must be an `output`.

`Charset` must be a `charset`.

`Newline` must be a `str`.

Example