Git Product home page Git Product logo

newtype-ops's Introduction

newtype-ops

License Documentation Crates.io Version Build Status

A operator-deriving macro for newtypes that is wartier than newtype_derive, and therefore better.[Citation needed]

pub struct Foo(i32);

newtype_ops! { [Foo] integer {:=} {^&}Self {^&}{Self i32} }

// alternatively
newtype_ops! { [Foo] {add sub mul div rem neg not bitand bitor bitxor} {:=} {^&}Self {^&}{Self i32} }

Installation

So for once I have finally decided to actually publish a crate this time.

Cargo.toml

[dependencies]
newtype-ops = "0.1"

Documentation

Funny thing, actually, pretty much the sole reason I published the crate was so that I could link to docs.rs.

See the documentation for newtype_ops!

License

WTFPL 2.0

newtype-ops's People

Contributors

exphp avatar

Stargazers

 avatar

Watchers

 avatar  avatar

newtype-ops's Issues

Can maybe enable OpAssign impls for borrowed RHS

In the documentation I note that these invocations are ignored:

newtype_ops! { [Foo] add = ^Self &Self } // Silently ignored [b]
newtype_ops! { [Foo] add = ^Self &i32  } // Silently ignored [b]

because at the time this crate was originally written (many years ago!), primitive integers and floats were missing OpAssign impls for borrowed Rhs types. These impls were added in 1.22.0.

There's probably no good excuse to continue ignoring these. However, adding them will require a semver major bump, because this can cause existing invocations of the macro to generate more impls, and it's possible that somebody could be wrapping a type that doesn't have these OpAssign impls.


This probably amounts to nothing more than deleting these lines:

newtype-ops/src/lib.rs

Lines 401 to 402 in c2763b4

// Make assign require a '^Self' receiver (form = [x.0])
(@postprocess::blacklist([{kind:assign} {recv_form:[&x.0]} $arg_form:tt $arg:tt] $($rest:tt)*)) => { };

(and adding tests of course)

Missing bitwise shifts

These are missing for no other reason than I'm a doo-doo head.

At the same time it's not entirely sure what operator groups they should belong to. To be honest I seldom use bitwise ops for anything except sets, and shifts don't work on sets.

Perhaps I like this:

  • new group: shift = {shl shr}
  • new group: set = {bitand bitor bitxor}
  • bitwise = {shift set not}

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.