Crates.io | negative-impl |
lib.rs | negative-impl |
version | 0.1.6 |
source | src |
created_at | 2020-11-17 06:20:50.611099 |
updated_at | 2024-08-23 17:12:28.502446 |
description | Negative trait implementations on stable Rust. |
homepage | |
repository | https://github.com/taiki-e/negative-impl |
max_upload_size | |
id | 313197 |
size | 32,186 |
Negative trait implementations on stable Rust.
This crate emulates the unstable negative_impls
feature
by generating a trait implementation with a condition that will never be true.
Add this to your Cargo.toml
:
[dependencies]
negative-impl = "0.1"
use negative_impl::negative_impl;
pub struct Type {}
#[negative_impl]
impl !Send for Type {}
#[negative_impl]
impl !Sync for Type {}
Currently this crate only supports auto traits.
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 {}
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.