Coder Social home page Coder Social logo

assert-impl's Introduction

Macro for static assert that types implement a trait or not.

Note: this macro can only be used inside function body due to restriction of Rust.

Example

Assuming you have the following definitions:

struct C;
struct Java;
struct JavaScript;
struct Python;
struct Rust;

trait StaticTyping {}
impl StaticTyping for C {}
impl StaticTyping for Java {}
impl StaticTyping for Rust {}

This should build:

assert_impl!(StaticTyping: C, Java, Rust);
assert_impl!(StaticTyping: C, Java, Rust, );
assert_impl!(!StaticTyping: JavaScript, Python);
assert_impl!(!StaticTyping: JavaScript, Python, );

But this should fail to build:

assert_impl!(StaticTyping: JavaScript);
assert_impl!(!StaticTyping: Rust);

assert-impl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

assert-impl's Issues

Need to support generic types

There are usecases for types like Foo<'a>, Bar<T: Clone> things like that. We should add support for that.

Syntax can be something like

assert_impl!(FancyTrait: for<'a> Foo<'a>, for<T: Clone> Bar<T>);

Add more extensive tests

Currently we rely on using doc test to ensure that violation of the assertion would correctly trigger compile failure. But doc test isn't really scalable, and with adding more complicated stuff (e.g. #1), we need a better way to do testing.

There is a wonderful crate compiletest_rs, but unfortunately it doesn't currently work on stable (see Manishearth/compiletest-rs#124), so we probably cannot use it for now...

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.