Negative trait implementations on stable Rust

unstable negative_impls feature

negative-impl

.

This crate emulates the unstable negative_impls feature by generating a trait implementation with a condition that will never be true.

Usage

Add this to your Cargo.toml:

[dependencies]
negative-impl = "0.1"

Compiler support: requires rustc 1.37+

Examples

use negative_impl::negative_impl;

pub struct Type {}

#[negative_impl]
impl !Send for Type {}
#[negative_impl]
impl !Sync for Type {}

Supported traits

Currently this crate only supports auto traits.

  • Send
  • Sync
  • Unpin
  • UnwindSafe
  • RefUnwindSafe

Limitations

Conflicting implementations

The following code cannot compile due to impl<T: Send> Trait for T and impl Trait for Type conflict.

use negative_impl::negative_impl;

pub struct Type {}

#[negative_impl]
impl !Send for Type {}

trait Trait {}

impl<T: Send> Trait for T {}
impl Trait for Type {}
error[E0119]: conflicting implementations of trait `Trait` for type `Type`:
  --> src/lib.rs:60:1
   |
14 | impl<T: Send> Trait for T {}
   | ------------------------- first implementation here
15 | impl Trait for Type {}
   | ^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Type`

The above code can be compiled using the unstable negative_impls feature.

#![feature(negative_impls)]

pub struct Type {}

impl !Send for Type {}

trait Trait {}

impl<T: Send> Trait for T {}
impl Trait for Type {}

Conditional negative impls

The current behavior of this crate with conditional negative impls is the same as the unstable negative_impls feature, but the unstable negative_impls feature plans to forbid it.

It's a great plan, but when it's implemented, this crate is unlikely to provide the same behavior due to the macro's limitation.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Versions

Find the latest versions by id

Information - Updated Jun 23, 2022

Stars: 7
Forks: 0
Issues: 0

tp-note rust based note taking application

Minimalist note taking with save and editing of your clipboard content as-well

tp-note rust based note taking application

A study note of Rust language

The Rust Programming Language

A study note of Rust language

An experimental no-alloc Rust GUI toolkit built on top of embedded-graphics

is to provide a cross-platform, no_std, non-allocating, composable UI framework

An experimental no-alloc Rust GUI toolkit built on top of embedded-graphics

mol-swatter is a python lib that uses rust nom to quickly parse through

mol chemical files, build adjacency graphs for the molecule, and match against various functional groups hard coded into the program

mol-swatter is a python lib that uses rust nom to quickly parse through

A no-std Rust modbus library

If you like to use Modbus TCP only:

A no-std Rust modbus library

A library to parse the x86 CPUID instruction, written in rust with no external dependencies

The implementation closely resembles the Intel CPUID manual description

A library to parse the x86 CPUID instruction, written in rust with no external dependencies

Rust TMP006/B Non-Contact Infrared (IR) Thermopile Temperature Sensor Driver

This is a platform agnostic Rust driver for the TMP006/TMP006B non-contact

Rust TMP006/B Non-Contact Infrared (IR) Thermopile Temperature Sensor Driver

rust-neon-blank: Node

js add-on example written in Rust

rust-neon-blank: Node

A cross platform media service library made in Rust for Node to easily and seamelessly...

A cross platform media service library made in Rust for Node to easily and seamelessly integrate with the operating systems media service API

A cross platform media service library made in Rust for Node to easily and seamelessly...

A simple mDNS resolver derived from simple-mdns, in async Rust with no

A simple mDNS resolver derived from simple-mdns) are intended to browse or query

A simple mDNS resolver derived from simple-mdns, in async Rust with no

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony...

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony Romano's docs

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony...

Non-official rust library to search Nyaa

si does not provide any APIs so I thought it would be cool to have a way to do so in Rust and that's why...

Non-official rust library to search Nyaa
Facebook Instagram Twitter GitHub Dribbble
Privacy