Attribute Macro display_as_proc_macro::with_template

source ·
#[with_template]
Expand description

Implement DisplayAs for a given type.

Why not use derive? Because we need to be able to specify which format we want to implement, and we might want to also use additional generic bounds.

You may use with_template in two different ways: inline or with a separate template file. To use an inline template, you provide your template as an argument, as in #[with_template("Vec(" self.x "," self.y "," self.z ",")]. The template consists of alternating strings and expressions, although you can also use if statements, for loops, or match expressions, although match expressions must use curly braces on each branch.

A template file is specified by giving the path relative to the current source file as a string argument: #[with_template("filename.html")]. There are a few hokey restrictions on your filenames.

  1. Your filename cannot have an embedded " character.
  2. Your string specifying the filename cannot be a “raw” string.
  3. You cannot use any characters (including a backslash) that need escaping in rust strings.

These constraints are very hokey, and may be lifted in the future. File a bug report if you have a good use for lifting these constraints.

The file itself will have a template like those above, but without the beginning or ending quotation marks. Furthermore, it is assumed that you are using raw strings, and that you use an equal number of # signs throughout.