-
-
Notifications
You must be signed in to change notification settings - Fork 5
mashing up idents with strings #11
Comments
I would accept a PR to add support for |
awesome! knowing that this is possible makes me a very happy camper. I'll see what I can do. thanks @dtolnay |
When running the tests as is locally I ran into the following error. Should this crate work on stable rust?
|
found a work around in your travis.yml file |
@dtolnay I got something working, but I wanted to give you an early heads up that I found an unrelated bug along the way. I learned a lot in this fun little exercise. You're macro for macro powers are quite impressive! The bug I ran into has has to do with literal strings and chars. I found that even after resolving an env var, the way the I haven't found a great way to work around that other than to call impl Concat {
fn mashup(&self) -> String {
- self.pieces.iter().map(ToString::to_string).collect()
+ self.pieces
+ .iter()
+ .map(|tt| match tt {
+ TokenTree::Literal(_) => tt.to_string().trim_matches('"').trim_matches('\'').into(),
+ _ => tt.to_string(),
+ }).collect() without any another additional changes I was able to make a failing test and then make it pass with this change. +#[test]
+fn test_lit_str() {
+ mashup! {
+ m["x"] = Foo "Bar";
+ }
+
+ m! {
+ struct "x";
+ }
+
+ let _ = FooBar;
+} Something of note for the I should be able to have something pull worthy by tomorrow. I have a working test +#[test]
+fn test_env_present() {
+ ::std::env::set_var("FOO", "bar"); // <- this doesn't do anything for our test :)
+ mashup! {
+ m["x"] = Lib env!("FOO");
+ }
+
+ m! {
+ struct "x";
+ }
+
+ let _ = Libbar;
+}
+ I just need to clean up the tokentree matching code. It works, but it could use some teeth cleaning :) |
scratch the note on changing test env expectations. I'll just use a var provided by cargo |
Thanks for publishing this for those awaiting concat_indents on stable. I have a usecase where I'd like to be able to materialize an indent from a crate name and idents. I'm not sure if that's outside the scope of this crate but I wanted to reach out in case this was already possible I just wasn't seeing it.
It's a problem not just a problem that's specific to me but also with rust cpython crates in general
https://dgrunwald.github.io/rust-cpython/doc/cpython/macro.py_module_initializer.html
specifically I'd like to be able to express something like this.
I feel like this should be solvable but maybe just not with the rust of today.
The text was updated successfully, but these errors were encountered: