Skip to main content

Formatter

Trait Formatter 

Source
pub trait Formatter {
    // Required method
    fn format<W: Write>(&self, f: &mut W, options: &FormatOptions) -> Result;

    // Provided method
    fn to_formatted_string(&self, fmt: &FormatOptions) -> String { ... }
}
Expand description

Common interface for writing a value to a Write target using a FormatOptions descriptor.

Implementations exist for OrderedFloat<f64> (the underlying numeric representation of an angle) and for each public coordinate type. Most callers will reach for Formatter::to_formatted_string when they want an owned String.

§Examples

use lat_long::{Angle, Longitude, fmt::{FormatOptions, Formatter}};

let lon = Longitude::new(-122, 19, 59.0).unwrap();
let bare = lon.to_formatted_string(&FormatOptions::dms_bare());
assert!(bare.starts_with('-'));

Required Methods§

Source

fn format<W: Write>(&self, f: &mut W, options: &FormatOptions) -> Result

Write self to f according to options.

Implementations should respect every relevant field of options (kind, precision, labels) and produce no extraneous whitespace.

Provided Methods§

Source

fn to_formatted_string(&self, fmt: &FormatOptions) -> String

Convenience helper: render self into a new String.

This is implemented in terms of Formatter::format and a String buffer, so it cannot fail in practice.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Formatter for OrderedFloat<f64>

Source§

fn format<W: Write>(&self, f: &mut W, options: &FormatOptions) -> Result

Implementors§