fn generate_swell_token_stream(fn_ptrs: &Vec<FnPtr>) -> proc_macro2::TokenStream {
            let Compartments {
                names,
                fn_ptr_signatures,
                methods,
            } = build_compartments(fn_ptrs, &phf::phf_set![], &ADDITIONAL_SAFE_SWELL_FUNCTIONS);
            let windows_functions: Vec<_> = fn_ptrs
                .iter()
                .filter_map(|p| {
                    if !WIN32_SWELL_FUNCTIONS.contains(p.name.to_string().as_str()) {
                        return None;
                    }
                    // It's important to use `extern "system"` here, otherwise the linker will
                    // complain about missing externals on Windows 32-bit.
                    Some(generate_function(&p, p.name.clone(), "system"))
                })
                .collect();
            let windows_methods: Vec<_> = fn_ptrs
                .iter()
                .filter_map(|p| {
                    if !WIN32_SWELL_FUNCTIONS.contains(p.name.to_string().as_str()) {
                        return None;
                    }
                    Some(generate_method(
                        &p,
                        generate_swell_windows_method_body(&p, p.name.clone()),
                        &ADDITIONAL_SAFE_SWELL_FUNCTIONS,
                    ))
                })
                .collect();
            let total_fn_ptr_count = names.len() as u32;
            quote::quote! {
                //! This file is automatically generated by executing `cargo build --features generate`.
                //!
                //! **Make adjustments in `build.rs`, not in this file!**
                #![allow(clippy::many_single_char_names)]
                #![allow(clippy::too_many_arguments)]
                #![allow(clippy::type_complexity)]
                #![allow(non_upper_case_globals)]
                #![allow(non_camel_case_types)]
                #![allow(non_snake_case)]
                #![allow(unused_unsafe)]

                use crate::{bindings::root, PluginContext};

                /// This is the low-level API access point to all SWELL functions.
                ///
                /// SWELL is the Simple Windows Emulation Layer and is exposed by REAPER for Linux
                /// and Mac OS X.
                ///
                /// See [`Reaper`] for details how to use this struct (it's very similar).
                ///
                /// [`Reaper`]: struct.Reaper.html
                #[derive(Copy, Clone, Debug, Default)]
                pub struct Swell {
                    pub(crate) pointers: SwellFunctionPointers,
                    // The only reason why this can be None is that we want to support Default. We want Default
                    // in order to be able to create rustdoc example code in higher-level APIs without needing a
                    // proper plug-in context.
                    pub(crate) plugin_context: Option<PluginContext>,
                }

                impl Swell {
                    /// Loads all available SWELL functions from the given plug-in context.
                    ///
                    /// Returns a `Swell` instance which allows you to call these functions.
                    ///
                    /// On Windows, this function will not load any function pointers because
                    /// the methods in this struct delegate to the corresponding Windows functions.
                    ///
                    /// # Panics
                    ///
                    /// If this is Linux and the SWELL function provider is not available, this
                    /// function panics.
                    pub fn load(plugin_context: PluginContext) -> Swell {
                        #[cfg(target_family = "windows")]
                        {
                            Swell {
                                pointers: Default::default(),
                                plugin_context: Some(plugin_context)
                            }
                        }
                        #[cfg(target_family = "unix")]
                        {
                            let mut loaded_count = 0;
                            let get_func = plugin_context.swell_function_provider()
                                .expect("SWELL function provider not available");
                            let mut pointers = unsafe {
                                SwellFunctionPointers {
                                    loaded_count: 0,
                                    #(
                                        #names: std::mem::transmute(get_func(c_str_macro::c_str!(stringify!(#names)).as_ptr())),
                                    )*
                                }
                            };
                            #(
                                if pointers.#names.is_some() {
                                    loaded_count += 1;
                                }
                            )*
                            pointers.loaded_count = loaded_count;
                            Swell {
                                pointers,
                                plugin_context: Some(plugin_context)
                            }
                        }
                    }

                    #(
                        #[cfg(target_family = "unix")]
                        #methods
                    )*

                    #(
                        #[cfg(target_family = "windows")]
                        #windows_methods
                    )*
                }

                /// Container for the SWELL function pointers.
                #[derive(Copy, Clone, Default)]
                pub struct SwellFunctionPointers {
                    pub(crate) loaded_count: u32,
                    #(
                        pub #names: Option<#fn_ptr_signatures>,
                    )*
                }

                impl SwellFunctionPointers {
                    pub(crate) const TOTAL_COUNT: u32 = #total_fn_ptr_count;
                }

                #[cfg(target_family = "windows")]
                mod windows {
                    use crate::bindings::root;

                    #(
                        #windows_functions
                    )*
                }
            }
        }
/// Generates the token stream. All of this could also be done in a procedural macro but
/// I prefer the code generation approach for now.
Generates the token stream. All of this could also be done in a procedural macro but
I prefer the code generation approach for now.
Generates the token stream . All of this could also be done in a procedural macro but I prefer the code generation approach for now .
fn generate_swell_token_stream(fn_ptrs: &Vec<FnPtr>) -> proc_macro2::TokenStream {
            let Compartments {
                names,
                fn_ptr_signatures,
                methods,
            } = build_compartments(fn_ptrs, &phf::phf_set![], &ADDITIONAL_SAFE_SWELL_FUNCTIONS);
            let windows_functions: Vec<_> = fn_ptrs
                .iter()
                .filter_map(|p| {
                    if !WIN32_SWELL_FUNCTIONS.contains(p.name.to_string().as_str()) {
                        return None;
                    }
                    // It's important to use `extern "system"` here, otherwise the linker will
                    // complain about missing externals on Windows 32-bit.
                    Some(generate_function(&p, p.name.clone(), "system"))
                })
                .collect();
            let windows_methods: Vec<_> = fn_ptrs
                .iter()
                .filter_map(|p| {
                    if !WIN32_SWELL_FUNCTIONS.contains(p.name.to_string().as_str()) {
                        return None;
                    }
                    Some(generate_method(
                        &p,
                        generate_swell_windows_method_body(&p, p.name.clone()),
                        &ADDITIONAL_SAFE_SWELL_FUNCTIONS,
                    ))
                })
                .collect();
            let total_fn_ptr_count = names.len() as u32;
            quote::quote! {
                //! This file is automatically generated by executing `cargo build --features generate`.
                //!
                //! **Make adjustments in `build.rs`, not in this file!**
                #![allow(clippy::many_single_char_names)]
                #![allow(clippy::too_many_arguments)]
                #![allow(clippy::type_complexity)]
                #![allow(non_upper_case_globals)]
                #![allow(non_camel_case_types)]
                #![allow(non_snake_case)]
                #![allow(unused_unsafe)]
                use crate::{bindings::root, PluginContext};
                /// This is the low-level API access point to all SWELL functions.
                ///
                /// SWELL is the Simple Windows Emulation Layer and is exposed by REAPER for Linux
                /// and Mac OS X.
                ///
                /// See [`Reaper`] for details how to use this struct (it's very similar).
                ///
                /// [`Reaper`]: struct.Reaper.html
                #[derive(Copy, Clone, Debug, Default)]
                pub struct Swell {
                    pub(crate) pointers: SwellFunctionPointers,
                    // The only reason why this can be None is that we want to support Default. We want Default
                    // in order to be able to create rustdoc example code in higher-level APIs without needing a
                    // proper plug-in context.
                    pub(crate) plugin_context: Option<PluginContext>,
                }
                impl Swell {
                    /// Loads all available SWELL functions from the given plug-in context.
                    ///
                    /// Returns a `Swell` instance which allows you to call these functions.
                    ///
                    /// On Windows, this function will not load any function pointers because
                    /// the methods in this struct delegate to the corresponding Windows functions.
                    ///
                    /// # Panics
                    ///
                    /// If this is Linux and the SWELL function provider is not available, this
                    /// function panics.
                    pub fn load(plugin_context: PluginContext) -> Swell {
                        #[cfg(target_family = "windows")]
                        {
                            Swell {
                                pointers: Default::default(),
                                plugin_context: Some(plugin_context)
                            }
                        }
                        #[cfg(target_family = "unix")]
                        {
                            let mut loaded_count = 0;
                            let get_func = plugin_context.swell_function_provider()
                                .expect("SWELL function provider not available");
                            let mut pointers = unsafe {
                                SwellFunctionPointers {
                                    loaded_count: 0,
                                    #(
                                        #names: std::mem::transmute(get_func(c_str_macro::c_str!(stringify!(#names)).as_ptr())),
                                    )*
                                }
                            };
                            #(
                                if pointers.#names.is_some() {
                                    loaded_count += 1;
                                }
                            )*
                            pointers.loaded_count = loaded_count;
                            Swell {
                                pointers,
                                plugin_context: Some(plugin_context)
                            }
                        }
                    }
                    #(
                        #[cfg(target_family = "unix")]
                        #methods
                    )*
                    #(
                        #[cfg(target_family = "windows")]
                        #windows_methods
                    )*
                }
                /// Container for the SWELL function pointers.
                #[derive(Copy, Clone, Default)]
                pub struct SwellFunctionPointers {
                    pub(crate) loaded_count: u32,
                    #(
                        pub #names: Option<#fn_ptr_signatures>,
                    )*
                }
                impl SwellFunctionPointers {
                    pub(crate) const TOTAL_COUNT: u32 = #total_fn_ptr_count;
                }
                #[cfg(target_family = "windows")]
                mod windows {
                    use crate::bindings::root;
                    #(
                        #windows_functions
                    )*
                }
            }
        }
fn generate_swell_token_stream ( fn_ptrs : & Vec < FnPtr > ) -> proc_macro2 :: TokenStream { let Compartments { names , fn_ptr_signatures , methods , } = build_compartments ( fn_ptrs , & phf :: phf_set ! [ ] , & ADDITIONAL_SAFE_SWELL_FUNCTIONS ) ; let windows_functions : Vec < _ > = fn_ptrs . iter ( ) . filter_map ( | p | { if ! WIN32_SWELL_FUNCTIONS . contains ( p . name . to_string ( ) . as_str ( ) ) { return None ; } // It's important to use `extern "system"` here, otherwise the linker will // complain about missing externals on Windows 32-bit. Some ( generate_function ( & p , p . name . clone ( ) , " " ) ) } ) . collect ( ) ; let windows_methods : Vec < _ > = fn_ptrs . iter ( ) . filter_map ( | p | { if ! WIN32_SWELL_FUNCTIONS . contains ( p . name . to_string ( ) . as_str ( ) ) { return None ; } Some ( generate_method ( & p , generate_swell_windows_method_body ( & p , p . name . clone ( ) ) , & ADDITIONAL_SAFE_SWELL_FUNCTIONS , ) ) } ) . collect ( ) ; let total_fn_ptr_count = names . len ( ) as u32 ; quote :: quote ! { //! This file is automatically generated by executing `cargo build --features generate`. //! **Make adjustments in `build.rs`, not in this file!** [ allow ( clippy many_single_char_names ) ] [ allow ( clippy too_many_arguments ) ] [ allow ( clippy type_complexity ) ] [ allow ( non_upper_case_globals ) ] [ allow ( non_camel_case_types ) ] [ allow ( non_snake_case ) ] [ allow ( unused_unsafe ) ] use crate { bindings root PluginContext } /// This is the low-level API access point to all SWELL functions. /// SWELL is the Simple Windows Emulation Layer and is exposed by REAPER for Linux /// and Mac OS X. /// See [`Reaper`] for details how to use this struct (it's very similar). /// [`Reaper`]: struct.Reaper.html [ derive ( Copy Clone Debug Default ) ] pub struct Swell { pub ( crate ) pointers SwellFunctionPointers // The only reason why this can be None is that we want to support Default. We want Default // in order to be able to create rustdoc example code in higher-level APIs without needing a // proper plug-in context. pub ( crate ) plugin_context Option PluginContext } impl Swell { /// Loads all available SWELL functions from the given plug-in context. /// Returns a `Swell` instance which allows you to call these functions. /// On Windows, this function will not load any function pointers because /// the methods in this struct delegate to the corresponding Windows functions. /// # Panics /// If this is Linux and the SWELL function provider is not available, this /// function panics. pub fn load ( plugin_context PluginContext ) Swell { [ cfg ( target_family " " ) ] { Swell { pointers Default default ( ) plugin_context Some ( plugin_context ) } } [ cfg ( target_family " " ) ] { let mut loaded_count 0 let get_func plugin_context swell_function_provider ( ) expect ( " " ) let mut pointers unsafe { SwellFunctionPointers { loaded_count 0 ( names std mem transmute ( get_func ( c_str_macro c_str ( stringify ( names ) ) as_ptr ( ) ) ) ) } } ( if pointers names is_some ( ) { loaded_count 1 } ) pointers loaded_count loaded_count Swell { pointers plugin_context Some ( plugin_context ) } } } ( [ cfg ( target_family " " ) ] methods ) ( [ cfg ( target_family " " ) ] windows_methods ) } /// Container for the SWELL function pointers. [ derive ( Copy Clone Default ) ] pub struct SwellFunctionPointers { pub ( crate ) loaded_count u32 ( pub names Option fn_ptr_signatures ) } impl SwellFunctionPointers { pub ( crate ) const TOTAL_COUNT u32 total_fn_ptr_count } [ cfg ( target_family " " ) ] mod windows { use crate bindings root ( windows_functions ) } } }
Generates the token stream.
Generates the token stream .
fn_ptrs
&Vec<FnPtr>
fn_ptrs
&Vec<FnPtr>