Git Product home page Git Product logo

matr's Introduction

Matr

Matr (Metaprogramming with Associated Types in Rust, pronounced like "matter") is a metaprogramming library for Rust.

This is meant to be a sort of standard library for metaprogramming in Rust, providing basic types and algorithms, but with the expectation that users of this crate will want to define their own types and meta-functions; the meta-"type system" is designed to be extensible.

Apart from bool and type, all other meta-types defined here (i.e., the directories under src/) don't access anything beyond what a user of this library could, so they also serve as examples for users of this library on how to write their own meta-types.

It's also possible to define custom sub-traits of Kind with additional restrictions/capabilities, see EqualityComparableKind and Equals for an example.

This library uses traits (notably Expr<K>) for meta-values, so that the Rust typechecker can detect type errors in meta-functions (e.g. attempting to return an Expr<Bool> in a meta-function that should return an Expr<USize>). Since traits can't have trait parameters (only type parameters, that could be constrained via traits) each meta-type has an associated Kind struct (e.g. Bool for booleans).

At the time of writing (March 2023) this is still a work in progress, and requires a nightly version of rustc due to the use of #![feature(specialization)] and #![feature(const_trait_impl)] (that are not yet stabilized).

This is not an officially supported Google product.

Why not use const fns for metaprogramming?

If your use case is covered by const fns, it's simpler to use those instead of this. However, const fns can't compute types; if you're looking for a library to manipulate types you're in the right place.

This library also provides a ConstFn metatype that allows to also have a const fn as the result of the meta-computation.

That is meant to be used in cases where you have some shared logic between the code used to compute a type and to compute a ConstFn. If you only need the ConstFn, then this library is overkill for your use case, you should just use plain const fns instead.

Why not use macros for metaprogramming?

If your use case is covered by macros, it's simpler to use those instead of this. However, macros only have access to the AST and not to the full type information (which is possible using this library).

matr's People

Contributors

poletti-marco avatar

Stargazers

Cppshizoid avatar Pierre Fenoll avatar Gabriel Neagu avatar T545im avatar  avatar Tamim Uddin avatar ธนัท วงศ์สวัสดิ์ avatar Hyeokryeol Yang avatar Fernando Ribeiro avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

sarvex tempbottle

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.