anowell / interpolate

Very simple Rust string interpolation
MIT License
36 stars 3 forks source link

error: expected one of `!` or `[`, found `fmt` #11

Open shiftagain opened 3 years ago

shiftagain commented 3 years ago

If I run the example from the documentation in a new crate:

use interpolate::s;

fn main() {
    let name = "Hercules";
    let greet = s!("Hello, {name}");
}

I get the error error: expected one of `!` or `[`, found `fmt`

If I run cargo expand, it shows that it expands to:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
use interpolate::s;
fn main() {
    let name = "Hercules";
    let greet = {
        {
            let res = ::alloc::fmt::format(());
            res
        }
    };
}

Am I doing something wrong, or is it broken? I'd love to use this macro in my projects :)

naythanN commented 1 year ago

Did you solved it? I have the same issue.

anowell commented 1 year ago

@naythanN : I'd be curious to know why you might be interested in using this crate now, since Rust 1.58 introduced identifier capture for format strings. IMO, Rust 1.58 basically reduced this crate to:

use std::format as s;
use std::println as p;

I suppose this crate did support interpolating expressions, which isn't supported by format strings, but I had my hesitations, so I mostly agree with the Rust team choosing to only support identifiers.

That said, bringing this crate back to my attention caused me to revisit an original idea around prefixing string literals (e.g. f"Hello, {name}"), so I quickly hacked together an experimental implementation. Not sure if I'll do anything with it, but I thought I'd share.

Cheers!