Skip to content

Commit f858436

Browse files
committed
add
1 parent 0cc4bc7 commit f858436

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

examples/macro-to-string/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/macro-to-string/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "macro-to-string"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

examples/macro-to-string/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
macro_rules! s(($result:expr) => ($result.to_string()));
2+
3+
fn main() {
4+
let name = s!("Foo Bar");
5+
println!("Hello, {}!", name);
6+
}

pages/macro-to-string.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Macro to_string
3+
timestamp: 2024-01-17T09:30:01
4+
published: true
5+
description: Sometimes I get tired typing in to_string, especially in test cases so I wrote this macro.
6+
tags:
7+
- macro_rules!
8+
- macro
9+
- to_string
10+
---
11+
12+
Sometimes I get tired typing in `to_string`, especially in test cases so I wrote this macro.
13+
14+
![](examples/macro-to-string/src/main.rs)
15+
16+
I am a bit ambivalent as I don't like one-letter variables or functions name, but I want this to be short.
17+
18+
An besides I can search for `s!` if I am looking for all the uses.
19+

0 commit comments

Comments
 (0)