ouroboros_macro/generate/
drop.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::info_structures::StructInfo;
use proc_macro2::TokenStream;
use quote::quote;
use syn::Error;

pub fn create_drop_impl(info: &StructInfo) -> Result<TokenStream, Error> {
    let ident = &info.ident;
    let generics = &info.generics;
    let generic_args = info.generic_arguments();

    let mut where_clause = quote! {};
    if let Some(clause) = &generics.where_clause {
        where_clause = quote! { #clause };
    }
    Ok(quote! {
        impl #generics ::core::ops::Drop for #ident<#(#generic_args,)*> #where_clause {
            fn drop(&mut self) {
                unsafe { self.actual_data.assume_init_drop() };
            }
        }
    })
}