Skip to content

Commit

Permalink
Remove GraphWeak custom derive
Browse files Browse the repository at this point in the history
Deriving this trait caused "conflicting implementations of trait
`core::graph::GraphWeak<_, _>` for type `...`" with "downstream crates
may implement trait `core::graph::GraphRef<_, _>` for type `...`", which
made the custom derive unusable.

Nevertheless, GraphWeak trait should be small enough to implement
manually.
  • Loading branch information
pnevyk committed Aug 7, 2024
1 parent d40742a commit 8da5ac3
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions gryf-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,40 +283,6 @@ pub fn graph_ref(tokens: TokenStream) -> TokenStream {
TokenStream::from(implemented)
}

#[proc_macro_derive(GraphWeak, attributes(graph, gryf_crate))]
pub fn graph_weak(tokens: TokenStream) -> TokenStream {
let input = parse_macro_input!(tokens as DeriveInput);

let gryf = util::get_gryf_path(&input);

let name = &input.ident;
let field = util::get_graph_field(&input);

let field_name = field.ident.as_ref().unwrap();
let field_type = &field.ty;

let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
let impl_generics = util::augment_impl_generics_if_necessary(impl_generics, vec!["V", "E"]);
let where_clause = util::augment_where_clause(
where_clause,
vec![(field_type.clone(), quote! { #gryf::core::GraphWeak<V, E> })],
);

let implemented = quote! {
impl #impl_generics #gryf::core::GraphWeak<V, E> for #name #ty_generics #where_clause {
fn vertex_weak(&self, id: &Self::VertexId) -> Option<#gryf::core::WeakRef<'_, V>> {
<#field_type as #gryf::core::GraphWeak<V, E>>::vertex_weak(&self.#field_name, id)
}

fn edge_weak(&self, id: &Self::EdgeId) -> Option<#gryf::core::WeakRef<'_, E>> {
<#field_type as #gryf::core::GraphWeak<V, E>>::edge_weak(&self.#field_name, id)
}
}
};

TokenStream::from(implemented)
}

#[proc_macro_derive(GraphMut, attributes(graph, gryf_crate))]
pub fn graph_mut(tokens: TokenStream) -> TokenStream {
let input = parse_macro_input!(tokens as DeriveInput);
Expand Down

0 comments on commit 8da5ac3

Please sign in to comment.