Giter VIP home page Giter VIP logo

ifmt's Introduction

ifmt

A small crate which brings inline string interpolation to rust's standard formatting macros.

Getting started

To use ifmt in your project, add

[dependencies]
ifmt = "0.3.3"

to your Cargo.toml.

Examples

let four = 4;
iprintln!("four plus four is: " four + 4);
// four plus four is: 8
iprintln!("here's a hex number: 0x" 0xb0bi64 * 1321517i64 ;x);
// here's a hex number: 0xdeadbeef
iprintln!("here's a debugging value: " Some(four);?);
// here's a debugging value: Some(4)

Supported macros

format!      -> iformat!
print!       -> iprint!
println!     -> iprintln!
eprint!      -> ieprint!
eprintln!    -> ieprintln!
write!       -> iwrite!
writeln!     -> iwriteln!
panic!       -> ipanic!
format_args! -> iformat_args!

License

This project is licensed under the MIT license or the Apache 2.0 license at your option.

ifmt's People

Contributors

cad97 avatar ct-austin avatar dtolnay avatar pruthvikar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ifmt's Issues

Is in-literal style here to stay?

The docs describe it as "old", and I'm not sure if I should take this to mean deprecated. It's still more convenient to not have to terminate and restart the string literal each time I want to print something, esp. if I am editing and changing my mind about where in the string I want to put my expressions.

proc-macro panic

This is not a major showstopper but thought you should know.

I am using iwriteln! and if I just include a single &str the macro panics. Here is an example:

iwriteln!(&mut code, "}")?;

The error says unmatched }.

Then I tried this:

iwriteln!(&mut code, "abc }")?;

Still got a panic, but not the same message.

I worked around it by doing this:

iwriteln!(&mut code, "}" "")?;

So it appears that a variable or another expression is always required. If that is intentional adding that to the doc would help.

Great job by the way, as you can see I am doing some code-gen, ifmt is going to make it pretty easy to do.

Make it simpler to just print a value.

Hi! First of all, thanks for this lib. It is so nicer to write rust code using it!
Secondly, I think there is a small room for improvement. For example, why don't we allow the following code to compile?

iprintln!(canvas.code());

It should be converted either to iprintln!("{}", canvas.code()); or to iprintln!("{:?}", canvas.code());. I prefer the latter, but I'm ok with both. In any case, that would allow us for much simpler usage in many cases.

Thanks! :)

Fails to build with the latest nightly

https://crater-reports.s3.amazonaws.com/pr-72622/master%237726070fa755f660b5da3f82f46e07d9c6866f69/reg/cargo-crev-0.17.0/log.txt

[INFO] [stderr]    Compiling ifmt-impl v0.3.0
[INFO] [stderr] error: expected identifier
[INFO] [stderr]   --> /opt/rustwide/cargo-home/registry/src/github.com-1ecc6299db9ec823/ifmt-impl-0.3.0/src/lib.rs:87:16
[INFO] [stderr]    |
[INFO] [stderr] 87 |         pub fn $name(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
[INFO] [stderr]    |                ^^^^^
[INFO] [stderr] ...
[INFO] [stderr] 97 | def_ifmt_macro!(iformat, format);
[INFO] [stderr]    | --------------------------------- in this macro invocation
[INFO] [stderr]    |
[INFO] [stderr]    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
[INFO] [stderr] 
[INFO] [stderr] error: expected identifier
[INFO] [stderr]   --> /opt/rustwide/cargo-home/registry/src/github.com-1ecc6299db9ec823/ifmt-impl-0.3.0/src/lib.rs:87:16
[INFO] [stderr]    |
[INFO] [stderr] 87 |         pub fn $name(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
[INFO] [stderr]    |                ^^^^^
[INFO] [stderr] ...
[INFO] [stderr] 99 | def_ifmt_macro!(iprint, print);
[INFO] [stderr]    | ------------------------------- in this macro invocation
[INFO] [stderr]    |
[INFO] [stderr]    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
[INFO] [stderr] 
[INFO] [stderr] error: expected identifier
[INFO] [stderr]    --> /opt/rustwide/cargo-home/registry/src/github.com-1ecc6299db9ec823/ifmt-impl-0.3.0/src/lib.rs:87:16
[INFO] [stderr]     |
[INFO] [stderr] 87  |         pub fn $name(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
[INFO] [stderr]     |                ^^^^^
[INFO] [stderr] ...
[INFO] [stderr] 101 | def_ifmt_macro!(iprintln, println);
[INFO] [stderr]     | ----------------------------------- in this macro invocation
[INFO] [stderr]     |
[INFO] [stderr]     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
[INFO] [stderr] 
[INFO] [stderr] error: expected identifier
[INFO] [stderr]    --> /opt/rustwide/cargo-home/registry/src/github.com-1ecc6299db9ec823/ifmt-impl-0.3.0/src/lib.rs:87:16
[INFO] [stderr]     |
[INFO] [stderr] 87  |         pub fn $name(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
[INFO] [stderr]     |                ^^^^^
[INFO] [stderr] ...
[INFO] [stderr] 103 | def_ifmt_macro!(ieprint, eprint);
[INFO] [stderr]     | --------------------------------- in this macro invocation
[INFO] [stderr]     |
[INFO] [stderr]     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
[INFO] [stderr] 
[INFO] [stderr] error: expected identifier
[INFO] [stderr]    --> /opt/rustwide/cargo-home/registry/src/github.com-1ecc6299db9ec823/ifmt-impl-0.3.0/src/lib.rs:87:16
[INFO] [stderr]     |
[INFO] [stderr] 87  |         pub fn $name(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
[INFO] [stderr]     |                ^^^^^
[INFO] [stderr] ...
[INFO] [stderr] 105 | def_ifmt_macro!(ieprintln, eprintln);
[INFO] [stderr]     | ------------------------------------- in this macro invocation
[INFO] [stderr]     |
[INFO] [stderr]     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
[INFO] [stderr] 
[INFO] [stderr] error: expected identifier
[INFO] [stderr]    --> /opt/rustwide/cargo-home/registry/src/github.com-1ecc6299db9ec823/ifmt-impl-0.3.0/src/lib.rs:87:16
[INFO] [stderr]     |
[INFO] [stderr] 87  |         pub fn $name(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
[INFO] [stderr]     |                ^^^^^
[INFO] [stderr] ...
[INFO] [stderr] 107 | def_ifmt_macro!(iformat_args, format_args);
[INFO] [stderr]     | ------------------------------------------- in this macro invocation
[INFO] [stderr]     |
[INFO] [stderr]     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
[INFO] [stderr] 
[INFO] [stderr] error: expected identifier
[INFO] [stderr]    --> /opt/rustwide/cargo-home/registry/src/github.com-1ecc6299db9ec823/ifmt-impl-0.3.0/src/lib.rs:87:16
[INFO] [stderr]     |
[INFO] [stderr] 87  |         pub fn $name(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
[INFO] [stderr]     |                ^^^^^
[INFO] [stderr] ...
[INFO] [stderr] 109 | def_ifmt_macro!(ipanic, panic);
[INFO] [stderr]     | ------------------------------- in this macro invocation
[INFO] [stderr]     |
[INFO] [stderr]     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
[INFO] [stderr] 
[INFO] [stderr] error: aborting due to 7 previous errors
[INFO] [stderr] 
[INFO] [stderr] error: could not compile `ifmt-impl`.

From: rust-lang/rust#72622 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.