Skip to main content

Print

Trait Print 

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

    // Provided method
    fn to_source(&self) -> Result<String> { ... }
}
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

Write the canonical source spelling of self to out.

Provided Methods§

Source

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

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 String

Source§

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

Source§

impl Print for bool

Source§

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

Source§

impl Print for f32

Source§

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

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

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

Source§

impl Print for i64

Source§

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

Source§

impl Print for str

Source§

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

Source§

impl Print for u32

Source§

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

Source§

impl Print for u64

Source§

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

Source§

impl Print for usize

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

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

Source§

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

Source§

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

Implementors§