Skip to main content

Print

Trait Print 

Source
pub trait Print {
    // Required method
    fn print(&self, out: &mut dyn Write) -> Result<(), Error>;

    // Provided method
    fn to_source(&self) -> Result<String, Report> { ... }
}
Expand description

Write a value in the source spelling accepted by its Parse implementation.

Implementations must round-trip: parsing the printed text yields a value equal to self. When no such spelling exists, return fmt::Error rather than writing text that would parse differently.

fmt::Formatter implements fmt::Write, so a Display impl can forward to print.

Required Methods§

Source

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Write the canonical source spelling of self to out.

Provided Methods§

Source

fn to_source(&self) -> Result<String, Report>

Return the canonical source spelling of self as a string.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Print for NoInfo

Source§

fn print(&self, __vihaco_out: &mut dyn Write) -> Result<(), Error>

Source§

impl Print for String

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

§

impl Print for Type

Print the canonical spelling of each type (the short form where the parser accepts aliases, e.g. str and fn).

§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

§

impl Print for Value

Print a type-tagged value such as u64 3 or f64 -0.5.

Finite floats print as their shortest round-tripping decimal. NaN and the infinities print as f64_bits/f32_bits so the exact bit pattern (including NaN payloads) survives a reparse.

§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl Print for bool

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl Print for f32

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Print the shortest decimal that parses back to the same bits.

Non-finite values have no source spelling and fail.

Source§

impl Print for f64

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Print the shortest decimal that parses back to the same bits.

Non-finite values have no source spelling and fail.

Source§

impl Print for i32

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl Print for i64

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl Print for str

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl Print for u32

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl Print for u64

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl Print for usize

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl<A, B> Print for (A, B)
where A: Print, B: Print,

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl<T> Print for &T
where T: Print + ?Sized,

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl<T> Print for Box<T>
where T: Print + ?Sized,

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl<T> Print for Option<T>
where T: Print,

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

None prints as null. Some(x) prints as x, unless that spelling would itself be read as the null keyword.

Source§

impl<T> Print for Vec<T>
where T: Print,

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Source§

impl<V, Ty> Print for ProgramDirective<V, Ty>
where V: Print, Ty: Print,

Source§

fn print(&self, out: &mut dyn Write) -> Result<(), Error>

Implementors§