pub struct StyxWriter { /* private fields */ }Expand description
Low-level Styx output writer.
This writer handles the formatting logic for Styx output, including:
- Indentation and newlines
- Scalar quoting decisions
- Inline vs multi-line formatting
Implementations§
Source§impl StyxWriter
impl StyxWriter
Sourcepub fn with_options(options: FormatOptions) -> Self
pub fn with_options(options: FormatOptions) -> Self
Create a new writer with the given options.
Sourcepub fn finish_document(self) -> Vec<u8> ⓘ
pub fn finish_document(self) -> Vec<u8> ⓘ
Consume the writer and return the output bytes, ensuring a trailing newline. This matches CST formatter behavior for standalone documents.
Sourcepub fn finish_string(self) -> String
pub fn finish_string(self) -> String
Consume the writer and return the output as a String.
§Panics
Panics if the output is not valid UTF-8 (should never happen with Styx).
Sourcepub fn available_width(&self) -> usize
pub fn available_width(&self) -> usize
Calculate available width at current depth.
Sourcepub fn should_inline(&self) -> bool
pub fn should_inline(&self) -> bool
Check if we should use inline formatting at current depth.
Sourcepub fn write_indent(&mut self)
pub fn write_indent(&mut self)
Write indentation for the current depth.
Sourcepub fn write_newline_indent(&mut self)
pub fn write_newline_indent(&mut self)
Write a newline and indentation.
Sourcepub fn write_byte(&mut self, b: u8)
pub fn write_byte(&mut self, b: u8)
Write a single byte.
Sourcepub fn begin_struct(&mut self, is_root: bool)
pub fn begin_struct(&mut self, is_root: bool)
Begin a struct/object.
If is_root is true, no braces are written (implicit root object).
Sourcepub fn begin_struct_with_options(
&mut self,
is_root: bool,
force_multiline: bool,
)
pub fn begin_struct_with_options( &mut self, is_root: bool, force_multiline: bool, )
Begin a struct/object with explicit multiline control.
If is_root is true, no braces are written (implicit root object).
If force_multiline is true, the struct will never be inlined.
Sourcepub fn begin_struct_after_tag(&mut self, force_multiline: bool)
pub fn begin_struct_after_tag(&mut self, force_multiline: bool)
Begin a struct directly after a tag (no space before the brace).
Sourcepub fn field_key_raw(&mut self, key: &str) -> Result<(), &'static str>
pub fn field_key_raw(&mut self, key: &str) -> Result<(), &'static str>
Write a field key without quoting (raw).
Use this for keys that should be written exactly as-is, like @ for unit keys.
Sourcepub fn field_key(&mut self, key: &str) -> Result<(), &'static str>
pub fn field_key(&mut self, key: &str) -> Result<(), &'static str>
Write a field key.
Returns an error message if called outside of a struct context.
Sourcepub fn end_struct(&mut self) -> Result<(), &'static str>
pub fn end_struct(&mut self) -> Result<(), &'static str>
End a struct/object.
Returns an error message if called without a matching begin_struct.
Sourcepub fn end_seq(&mut self) -> Result<(), &'static str>
pub fn end_seq(&mut self) -> Result<(), &'static str>
End a sequence.
Returns an error message if called without a matching begin_seq.
Sourcepub fn write_null(&mut self)
pub fn write_null(&mut self)
Write a null/unit value.
Sourcepub fn write_bool(&mut self, v: bool)
pub fn write_bool(&mut self, v: bool)
Write a boolean value.
Sourcepub fn write_i128(&mut self, v: i128)
pub fn write_i128(&mut self, v: i128)
Write an i128 value.
Sourcepub fn write_u128(&mut self, v: u128)
pub fn write_u128(&mut self, v: u128)
Write a u128 value.
Sourcepub fn write_string(&mut self, s: &str)
pub fn write_string(&mut self, s: &str)
Write a string value with appropriate quoting.
Sourcepub fn write_char(&mut self, c: char)
pub fn write_char(&mut self, c: char)
Write a char value.
Sourcepub fn write_bytes(&mut self, bytes: &[u8])
pub fn write_bytes(&mut self, bytes: &[u8])
Write bytes as hex-encoded string.
Sourcepub fn write_variant_tag(&mut self, name: &str)
pub fn write_variant_tag(&mut self, name: &str)
Write a variant tag (e.g., @some).
Sourcepub fn write_scalar(&mut self, s: &str)
pub fn write_scalar(&mut self, s: &str)
Write a scalar value with appropriate quoting. Alias for write_string, for when you have a pre-existing scalar.
Sourcepub fn write_tag(&mut self, name: &str)
pub fn write_tag(&mut self, name: &str)
Write a tag (e.g., @string). Same as write_variant_tag.
Sourcepub fn clear_skip_before_value(&mut self)
pub fn clear_skip_before_value(&mut self)
Clear the skip_next_before_value flag. Call this when a tag’s payload is skipped (e.g., None for a unit variant).
Sourcepub fn begin_seq_after_tag(&mut self)
pub fn begin_seq_after_tag(&mut self)
Begin a sequence directly after a tag (no space before the paren).
Sourcepub fn write_doc_comment_and_key(&mut self, doc: &str, key: &str)
pub fn write_doc_comment_and_key(&mut self, doc: &str, key: &str)
Write a doc comment followed by a field key.
Multiple lines are supported (each line gets /// prefix).
Sourcepub fn write_doc_comment_and_key_raw(&mut self, doc: &str, key: &str)
pub fn write_doc_comment_and_key_raw(&mut self, doc: &str, key: &str)
Write a doc comment followed by a raw field key (no quoting).
Use this for keys like @ that should be written literally.
Sourcepub fn before_value(&mut self)
pub fn before_value(&mut self)
Handle separator before a value in a container.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StyxWriter
impl RefUnwindSafe for StyxWriter
impl Send for StyxWriter
impl Sync for StyxWriter
impl Unpin for StyxWriter
impl UnwindSafe for StyxWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);