microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
Public Member Functions | List of all members
microfmt::span_sink Class Reference

Output sink that writes formatted characters into a fixed-size contiguous memory buffer. More...

#include <microfmt.hpp>

Public Member Functions

constexpr span_sink (span< char > buf RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS) noexcept
 Constructs a span sink over a microfmt::span of character storage.
 
sink as_sink () noexcept RELOCO_LIFETIMEBOUND
 Creates a type-erased sink adapter pointing to this instance.
 
constexpr microfmt::string_view view () const noexcept RELOCO_LIFETIMEBOUND
 Returns a string view over the characters written so far.
 
constexpr size_t size () const noexcept
 Returns the total number of characters written so far.
 
constexpr size_t available () const noexcept
 Returns the remaining unwritten capacity in the buffer.
 
RELOCO_REINITIALIZES constexpr void reset () noexcept
 Resets the write offset back to the beginning of the buffer.
 

Detailed Description

Output sink that writes formatted characters into a fixed-size contiguous memory buffer.

Wraps an externally provided buffer (via microfmt::span or std::span) and exposes a non-owning, zero-allocation sink interface. Writes that exceed the remaining capacity are truncated safely.

Constructor & Destructor Documentation

◆ span_sink()

constexpr microfmt::span_sink::span_sink ( span< char > buf RELOCO_LIFETIMEBOUND  RELOCO_LIFETIME_CAPTURE_BY_THIS)
inlineexplicitconstexprnoexcept

Constructs a span sink over a microfmt::span of character storage.

Parameters
bufThe target character buffer view.

Member Function Documentation

◆ as_sink()

sink microfmt::span_sink::as_sink ( )
inlinenoexcept

Creates a type-erased sink adapter pointing to this instance.

Returns
A lightweight sink struct configured with a callback to append to this buffer.

◆ available()

constexpr size_t microfmt::span_sink::available ( ) const
inlineconstexprnoexcept

Returns the remaining unwritten capacity in the buffer.

Returns
Available space in bytes.

◆ reset()

RELOCO_REINITIALIZES constexpr void microfmt::span_sink::reset ( )
inlineconstexprnoexcept

Resets the write offset back to the beginning of the buffer.

◆ size()

constexpr size_t microfmt::span_sink::size ( ) const
inlineconstexprnoexcept

Returns the total number of characters written so far.

Returns
Current write offset in bytes.

◆ view()

constexpr microfmt::string_view microfmt::span_sink::view ( ) const
inlineconstexprnoexcept

Returns a string view over the characters written so far.

Returns
Non-owning view of the formatted output.

The documentation for this class was generated from the following file: