Skip to content

Commit

Permalink
implement rc
Browse files Browse the repository at this point in the history
  • Loading branch information
wx-csy committed Apr 6, 2021
1 parent 0647988 commit 708457b
Show file tree
Hide file tree
Showing 3 changed files with 869 additions and 60 deletions.
12 changes: 7 additions & 5 deletions ptr_eq-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extern crate proc_macro;
#[macro_use] extern crate syn;
#[macro_use] extern crate quote;
#[macro_use]
extern crate syn;
#[macro_use]
extern crate quote;

use proc_macro::TokenStream;
use syn::DeriveInput;
Expand All @@ -11,7 +13,7 @@ pub fn derive_ptr_eq(input: TokenStream) -> TokenStream {
let name = input.ident;
let (impl_gn, ty_gn, where_cl) = input.generics.split_for_impl();

let expanded = quote!{
let expanded = quote! {
unsafe impl #impl_gn PtrEq for #name #ty_gn #where_cl {}

// &T
Expand All @@ -31,7 +33,7 @@ pub fn derive_ptr_eq(input: TokenStream) -> TokenStream {
}

// &T and &T

impl #impl_gn ::core::cmp::PartialEq<&#name #ty_gn> for &#name #ty_gn #where_cl {
#[inline]
fn eq(&self, other: &&#name #ty_gn) -> bool {
Expand Down Expand Up @@ -114,4 +116,4 @@ pub fn derive_ptr_eq(input: TokenStream) -> TokenStream {
};

expanded.into()
}
}
17 changes: 4 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
#[macro_use]
extern crate ptr_eq_macro;

pub mod rc;

pub use ptr_eq_macro::PtrEq;

/// A marker trait for types that implement by-address comparisons, equality tests,
/// and hashes.
pub unsafe trait PtrEq { }

#[derive(PtrEq)]
pub struct Test(i32);

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
pub unsafe trait PtrEq {}
Loading

0 comments on commit 708457b

Please sign in to comment.