# Quick Thought: const{} blocks

**URL:** <https://internals.rust-lang.org/t/quick-thought-const-blocks/7803>\
**Category:** language design\
**Created:** [June 26, 2018, 2:57am UTC](https://internals.rust-lang.org/t/quick-thought-const-blocks/7803 "2018-06-26T02:57:38Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![canndrew](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/canndrew/32/1676_2.png) [@canndrew](https://internals.rust-lang.org/u/canndrew)\
**Post date:** [July 29, 2018, 6:30am UTC](https://internals.rust-lang.org/t/quick-thought-const-blocks/7803/9 "2018-07-29T06:30:42Z")

</div>

One neat use case for this would be implementing a generic `parse!` macro. We already have `FromStr` for types that can be parsed from strings, but it’s impossible to use at compile-time leading to things like [this crate](https://crates.io/crates/net-literals).

With `const` blocks this macro could simply expand to

```
const { FromStr::from_str("some string").unwrap() }

```

Then I could write code like:

```
let x: u32 = parse!("123");
let y: String = parse!("hello");
let x: PublicKey = parse!("tgta61gja8w7099b17bc33sp49n1zawr037p1n4n7n19qkmgtf9g");
// etc.

```

And have the parsing (and any errors) happen at compile time.

---

_[View the full topic](https://internals.rust-lang.org/t/quick-thought-const-blocks/7803)._
