Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Implement Clone and DeepClone for extern "Rust" fn #8109

Closed
wants to merge 1 commit into from
Closed

std: Implement Clone and DeepClone for extern "Rust" fn #8109

wants to merge 1 commit into from

Conversation

bluss
Copy link
Member

@bluss bluss commented 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.

Implement Clone and DeepClone for functions with 0 to 8 arguments.
@bluss
Copy link
Member Author

bluss commented Jul 29, 2013

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
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