Giter VIP home page Giter VIP logo

Comments (3)

TheDan64 avatar TheDan64 commented on May 26, 2024

Working with heterogeneous collections is a pain in rust.. We could also provide a macro which simplifies the process for the user. (We may even want this earlier than 0.3.0)

For example,

let values = mixed_value_array!(BasicValue, [
    float_value,
    int_value,
    ...
]);

If we do end up adding this macro, I'd strongly consider switching the current homogeneous function params from say, &[&BasicValue] to &[BasicValueEnum] since the former generally requires an extra heap allocation (unless you happen to have a fixed size of values on the stack, which probably isn't realistic) for the extra trait indirection which could be avoided.

Then, this macro could expand to something like let values: Vec<BasicValueEnum> = array.iter().map(|val| val.into()).collect(). Might need associated type to derive BasicValueEnum from BasicValue, though.

from inkwell.

71 avatar 71 commented on May 26, 2024

The example function! macro you showed above would require the power brought by proc_macro, but it can be achieved similarly using a Lisp-like syntax (like clap.rs) with the macro_rules system.

Here's an example of doing dynamic code generation using this syntax: primitives.rs (note: it's part of a legacy compiler I wrote last year, the code is ugly in some places). The macro itself is defined here.

from inkwell.

TheDan64 avatar TheDan64 commented on May 26, 2024

Proc macros are probably fine; I don't expect to get to this issue before Macros 2.0 lands in stable(it seems pretty close: rust-lang/rust#38356), but who knows.

from inkwell.

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.