Crates.io | bind_it |
lib.rs | bind_it |
version | 0.1.3 |
source | src |
created_at | 2022-04-01 18:58:35.354318 |
updated_at | 2022-04-01 21:09:10.094123 |
description | A macro that allows impl traits in let/static/const bindings until they actually stabilized |
homepage | |
repository | |
max_upload_size | |
id | 560474 |
size | 8,806 |
A macro that allows using impl traits in bindings.
Currently supported statements: let
, const
(with some limitations mentioned below), static
.
This crate will be replaced by impl_trait_in_bindings feature in future,
but there is still a long way to reimplement and stabilize it.
#![feature(type_alias_impl_trait)]
#[macro_use]
extern crate bind_it;
fn main() {
bind_it!( let x: impl std::fmt::Display = true; );
// fails, even x variable is initialized with a boolean, its type is hidden behind `Display` trait,
// and the only thing that we can do - display x
// assert!(x);
// works
println!("{x}")
}
rustc 1.61.0-nightly (c5cf08d37 2022-03-30)
with #![feature(type_alias_impl_trait)]
enabled
bind_it! {
let _: impl std::fmt::Display = if rand::random() > 0.5 {
"qwe"
} else {
5u8
};
};
Despite of that fact that both &str
and u8
implement Display
trait, we need to determine ONE concrete type in the compile time.