Giter Site home page Giter Site logo

New API for using atoms about rustler HOT 9 CLOSED

rusterlium avatar rusterlium commented on April 27, 2024 3
New API for using atoms

from rustler.

Comments (9)

jorendorff avatar jorendorff commented on April 27, 2024 1

@scrogson pointed out that Rust keywords (like true and false) won't work with this kind of setup.

So here is another possible idea:

declare_atom_mod!(atoms {ok, ponies, true as true_atom, false as false_atom})

To use it, you would say atoms::ok(), atoms::true_atom(), etc.

from rustler.

jorendorff avatar jorendorff commented on April 27, 2024

Also - the current code for atom leaks an environment, types::atom::ATOM_ENV.

from rustler.

jorendorff avatar jorendorff commented on April 27, 2024

@hansihe Implemented this. The patch adds a bunch of functions types::atom::{ok, error, badarg, ...}

I decided on semicolons instead of commas because semicolons are usual for declarations, and trailing is better than separating. (Supporting an optional trailing comma in a Rust macro is weirdly hard.)

from rustler.

hansihe avatar hansihe commented on April 27, 2024

Great work! What do you think about removing the old NIF creation functions? This way seems to be superior in almost every way.

from rustler.

jorendorff avatar jorendorff commented on April 27, 2024

Taking a look at that now...

from rustler.

jorendorff avatar jorendorff commented on April 27, 2024

OK, 82f30c8 is my attempt. It replaces the old functions with two new ones. Take a look.

from rustler.

jorendorff avatar jorendorff commented on April 27, 2024

Two quirks about rustler_atoms!:

  • If you call it twice in the same scope, you get errors, because all the functions share a cache (by design) and we call it RUSTLER_ATOMS. There can't be two things with that name in the same scope.

  • The functions it creates are all public. Nothing else in Rust is public by default.

I think these are acceptable. Or, we could change the macro to declare a module of functions, instead of just functions. That would address both issues, but it's a little wordier to use:

// Current design
rustler_atoms! {
    atom wine;
    atom cheese;
}

// Alternative design
rustler_atoms_mod! {
    mod france_atoms {  // module is private by default
        atom wine;  // seems ok for these to be public by default
        atom cheese;
    }
}
use self::france_atoms::*;

from rustler.

OvermindDL1 avatar OvermindDL1 commented on April 27, 2024

Could support both?

from rustler.

hansihe avatar hansihe commented on April 27, 2024

Alternatively, atoms could have a pub modifier:

rustler_atoms! {
    pub atom wine;
    pub atom cheese;
}

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.