| Crates.io | interpolate |
| lib.rs | interpolate |
| version | 0.2.3 |
| created_at | 2017-09-13 04:32:36.173827+00 |
| updated_at | 2018-11-05 05:46:13.934239+00 |
| description | A simple form of string interpolation |
| homepage | |
| repository | https://github.com/anowell/interpolate |
| max_upload_size | |
| id | 31546 |
| size | 10,273 |
A simple form of Rust string interpolation, e.g., s!("Today is {date}").
Note: interpolate currently requires some experimental functionality in nightly.
#![feature(proc_macro_hygiene)]
use interpolate::s;
let name = "Jane";
let fav_num = 32;
let greeting = s!("{name}'s favorite number is {fav_num}");
Escaping braces is accomplished similar to escaping other format strings in rust.
The literal characters { and } may be included in a string by preceding them with the same character. For example, the { character is escaped with {{ and the } character is escaped with }}.
The goal of interpolate is to provide basic string interpolation functionality with a very light-weight syntax.
It is not:
format!, println!, and related macrosI created this after a working on a CLI tools where I used format! a LOT.
I really wanted something lighter weight like Scala's s"Today is $date", so
I decided to experiment here, with the idea of possibly adding to the
discussions around strings (like
allowing literals to be used as String
and custom string literals.
I frequently find myself wondering if any of these ideas could have a more central role in rust:
println!("Hello {name}") to basically mean println!("Hello {name}", name=name)let full_name = s"{first_name} {last_name}" instead of format!("{} {}", first_name, last_name)let msg = s"Hello" instead of "Hello".to_string()