Code Monkey home page Code Monkey logo

nameof's People

Contributors

a1-triard avatar bash avatar enoughtea avatar silentbyte 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

Watchers

 avatar  avatar

nameof's Issues

Fails to compile with unsafe symbols

Given this code:

static mut TEST: u8 = 0;

fn main() {
    println!("{}", ::nameof::name_of!(TEST));
}

the compiler fails with this error:

error[E0133]: use of mutable static is unsafe and requires unsafe function or block
 --> src/main.rs:4:20
  |
4 |     println!("{}", ::nameof::name_of!(TEST));
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^ use of mutable static
  |
  = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
  = note: this error originates in the macro `::nameof::name_of` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0133`.
error: could not compile `bug-repro-rust-nameof-unsafe` due to previous error

Support `Self` or suppress `clippy::use_self` warning

It's currently not possible to use name_of_type!(Self) to get the actual type name. If there is a way to support this, that would be great, but until then, it would be nice to automatically suppress clippy::use_self warning in the macro.

Versioning issue with Rust 2018 changes

The release should have been a feature release, because a crate might depend on the new functionality introduced with 1.0.2 (being able to use name_of!(type ...) without importing name_of_type!).

This might be an issue in the following situation:

Given that crate A depends on crate B and the following versions:

crate Cargo.toml Cargo.lock
crate A - 1.0.1
crate B 1.0 -

When crate B uses the new feature from 1.0.2, crate A fails to build.

I recommend releasing two new versions:

  • 1.0.3 (Identical to 1.0.1)
  • 1.1.0 (Identical to 1.0.2)

Also 1.0.2 should be yanked from crates.io.


Co-written-by: @bash

Originally posted by @jeremystucki in #1 (comment)

unused borrow that must be used

warning: unused borrow that must be used
   --> /home/julian/.cargo/registry/src/github.com-1ecc6299db9ec823/nameof-1.2.1/src/lib.rs:86:13
    |
82  | / macro_rules! name_of {
83  | |     // Covers Bindings
84  | |     ($n: ident) => {{
85  | |         let _ = || {
86  | |             &$n;
    | |             ^^^ the borrow produces a value
...   |
110 | |     }};
111 | | }
    | |_- in this expansion of `name_of!`
    |
   ::: src/keyboard.rs:202:45
    |
202 |                   debug_tuple = f.debug_tuple(name_of!(XkbSym));
    |                                               ---------------- in this macro invocation

Enum tag support

Hi,
I'm trying to implement Debug or Format for enums (yes, I know about the derive) and
don't want to hardcode enum tag names as strings.
Potentially, enum tags can change names in future and I want to be sure that print-ed values will follow names.
Was thinking about using nameof for this. For instance:

    enum Color {
        Red(i32),
        Green(i32),
        Blue(i32),
    }
   
    name_of!(enum Color::Green(42));
   // or
   tag_of!(Color::Green(42));

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.