boost::capy::any_write_sink

Type‐erased wrapper for any WriteSink.

Synopsis

class any_write_sink;

Description

This class provides type erasure for any type satisfying the WriteSink concept, enabling runtime polymorphism for sink write operations. It uses cached awaitable storage to achieve zero steady‐state allocation after construction.

The wrapper supports two construction modes: ‐ Owning: Pass by value to transfer ownership. The wrapper allocates storage and owns the sink. ‐ Reference: Pass a pointer to wrap without ownership. The pointed‐to sink must outlive this wrapper.

Awaitable Preallocation

The constructor preallocates storage for the type‐erased awaitable. This reserves all virtual address space at server startup so memory usage can be measured up front, rather than allocating piecemeal as traffic arrives.

Immediate Completion

Operations complete immediately without suspending when the buffer sequence is empty, or when the underlying sink's awaitable reports readiness via await_ready.

Thread Safety

Not thread‐safe. Concurrent operations on the same wrapper are undefined behavior.

Example

// Owning - takes ownership of the sink
any_write_sink ws(some_sink{args...});

// Reference - wraps without ownership
some_sink sink;
any_write_sink ws(&sink);

const_buffer buf(data, size);
auto [ec, n] = co_await ws.write(std::span(&buf, 1));
auto [ec2] = co_await ws.write_eof();

Member Functions

Name

Description

any_write_sink [constructor]

Constructors

~any_write_sink [destructor]

Destructor.

operator= [deleted]

Move assignment operator.

has_value

Check if the wrapper contains a valid sink.

write

Initiate a complete write operation.

write_eof

write_eof overloads

write_some

Initiate a partial write operation.

operator bool

Check if the wrapper contains a valid sink.

Protected Member Functions

Name

Description

rebind

Rebind to a new sink after move.

See Also

any_write_stream, WriteSink

Created with MrDocs