dumbeq/
lib.rs

1//! # DumbEq
2//!
3//! dumb implementation of [`std::cmp::PartialEq`] and [`std::cmp::Eq`]
4//!
5//! DumbEq is always false.
6//!
7//! Example
8//! ```
9//! use dumbeq::*;
10//!
11//! #[derive(DumbEq, Debug)]
12//! pub struct Same;
13//!
14//! assert!(Same != Same, "not the same");
15//! ```
16
17extern crate proc_macro;
18use quote::quote;
19use syn::DeriveInput;
20
21#[proc_macro_derive(DumbEq)]
22pub fn dumb_eq_macro_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
23    let ast: DeriveInput = match syn::parse(input).map_err(|e| Into::<proc_macro::TokenStream>::into(e.to_compile_error())) {
24        Ok(ast) => ast,
25        Err(ast) => return ast
26    };
27    let name = ast.ident;
28    quote! {
29        impl std::cmp::PartialEq for #name {
30            fn eq(&self, other: &#name) -> bool {
31                false
32            }
33        }
34        impl std::cmp::Eq for #name {}
35    }
36    .into()
37}