Skip to content

Using pass-through formatting in Display #38

@nyurik

Description

@nyurik

Is there a way to generate this Display implementation? Note that this is not a write!(f, "{0}", v), but rather v.fmt(f) call.

use std::fmt;

pub enum Term {
    Int(i32),
    Float(f64),
    Str(String),
}

impl fmt::Display for Term {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Int(v) => v.fmt(f),
            Self::Float(v) => v.fmt(f),
            Self::Str(v) => v.fmt(f),
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions