Skip to content

Documentation: write_fmt is unclear #15830

Closed
@kornelski

Description

@kornelski

I'm trying to upgrade code that worked in 0.10/0.11-pre (implementation of fmt::Show):

write!(formatter.buf, "\\#{:02x}{:02x}{:02x}", self.r, self.g, self.b),

I've found a write_fmt method that sounds like what I need, but it's undocumented:

http://doc.rust-lang.org/core/fmt/struct.Formatter.html#method.write_fmt

Linked Arguments documentation suggests usnig format_args!():

http://doc.rust-lang.org/core/fmt/struct.Arguments.html

but the usage I'd expect:

formatter.write_fmt(format_args!("\\#{:02x}{:02x}{:02x}", self.r, self.g, self.b)),

fails with "format argument must be a string literal.", which left me lost. If really supports only literals as arguments then it's totally useless, but if I'm doing something wrong, then the docs/compiler don't help me figure this out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions