Registry Mirror
Skip to content

Conversation

@bluss

@bluss bluss commented Jul 29, 2013

Copy link
Copy Markdown
Contributor

Implement Clone and DeepClone for functions with 0 to 8 arguments. extern fn() is implicitly copyable so it's simple, except there is no way to implement it generically over #n function arguments.

Allows deriving of Clone on structs containing extern "Rust" fn.

Implement Clone and DeepClone for functions with 0 to 8 arguments.
@bluss

bluss commented Jul 29, 2013

Copy link
Copy Markdown
Contributor Author

Cloning closures when possible would be great too (issue #8025). Probably better postponed for closure reform?

// clone a &'static fn
macro_rules! closure_clone(
    ($($A:ident),*) => (
        impl<$($A,)* Ret_Type> Clone for &'static fn($($A),*) -> Ret_Type {
            /// Return a copy of a captureless closure
            #[inline]
            fn clone(&self) -> &'static fn($($A),*) -> Ret_Type {
                unsafe {
                    let closure: raw::Closure = cast::transmute_copy(self);
                    assert!(ptr::is_null(closure.env));
                    cast::transmute(closure)
                }
            }
        }
    )
)

bors added a commit that referenced this pull request Jul 29, 2013
Implement Clone and DeepClone for functions with 0 to 8 arguments.  `extern fn()` is implicitly copyable so it's simple, except there is no way to implement it generically over #n function arguments.

Allows deriving of Clone on structs containing `extern "Rust" fn`.
@bors bors closed this Jul 29, 2013
U007D pushed a commit to U007D/rust-mos that referenced this pull request Aug 21, 2026
8109: Make ast editing more ergonomic r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants