Giter Site home page Giter Site logo

impl Debug for NifTerm about rustler HOT 9 CLOSED

jorendorff avatar jorendorff commented on April 27, 2024
impl Debug for NifTerm

from rustler.

Comments (9)

jorendorff avatar jorendorff commented on April 27, 2024

erlang_nif-sys doesn't expose enif_snprintf because it takes a variable number of arguments. However, I hacked this into erlang_nif-sys/lib.rs and it worked:

extern "C" {
    pub fn enif_snprintf(str: *mut c_char, size: size_t, format: *const c_char, term: ERL_NIF_TERM) -> c_int;
}

I think enif_snprintf is new in Erlang/OTP 19, which maybe means we should put it behind a feature flag. Everything else works in Erlang/OTP 18 and up.

from rustler.

jorendorff avatar jorendorff commented on April 27, 2024

See 7ca1e09.

from rustler.

scrogson avatar scrogson commented on April 27, 2024

Could this be something we could only make available when using in debug mode? If you attempt to use in release mode it would not compile?

from rustler.

hansihe avatar hansihe commented on April 27, 2024

No, the debug trait simply describes what happens when you try to debug print something. I don't think there is any reason this should only be available in release mode.

from rustler.

scrogson avatar scrogson commented on April 27, 2024

@hansihe I think you misunderstood me? I was saying that the Debug trait impl should only be available if the crate is compiled in debug (default) mode. If the crate is compiled in release mode, any debug formatting left in could throw a compile error.

I'm not even sure this is possible or a good idea, just throwing it out there.

But also putting it behind a feature could be a nice way to make it optional.

from rustler.

hansihe avatar hansihe commented on April 27, 2024

Seeing as no other debug implementations do this, I don't think we should do it either.

from rustler.

jorendorff avatar jorendorff commented on April 27, 2024

I just found out that Rust does support varargs for extern "C" functions. So this will be pretty easy, it starts with uncommenting a few lines in erlang_nif-sys.

from rustler.

jorendorff avatar jorendorff commented on April 27, 2024

rusterlium/erlang_nif-sys#23

from rustler.

hansihe avatar hansihe commented on April 27, 2024

This was resolved a while ago.

from rustler.

Related Issues (20)

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.