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

Core Lib Documentation: Clone module #6665

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

TAdev0
Copy link
Contributor

@TAdev0 TAdev0 commented Nov 15, 2024

No description provided.

TAdev0 and others added 5 commits October 30, 2024 13:44
Co-authored-by: Mathieu <60658558+enitrat@users.noreply.github.com>
Co-authored-by: Mathieu <60658558+enitrat@users.noreply.github.com>
Co-authored-by: Mathieu <60658558+enitrat@users.noreply.github.com>
@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor

@enitrat enitrat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @TAdev0)


corelib/src/clone.cairo line 38 at r1 (raw file):

//! ```

/// `Clone` trait defines the interface for cloning values.

I would add more details than just this

/// A common trait for the ability to explicitly duplicate an object.
///
/// Differs from `Copy` in that `Copy` is implicit and inexpensive, while
/// `Clone` is always explicit and may or may not be expensive.
///
/// Since `Clone` is more general than `Copy`, you can automatically make anything
/// `Copy` be `Clone` as well.
///
/// ## Derivable
///
/// This trait can be used with `#[derive]` if all fields are `Clone`. The `derive`d
/// implementation of `Clone` calls `clone` on each field.
///

Question to @orizi: what's the compiler behavior when deriving a trait on a generic struct?

Would it be true to say that "For a generic struct, #[derive] implements Clone conditionally by adding bound Clone on generic parameters." (as in Rust) ?


corelib/src/clone.cairo line 40 at r1 (raw file):

/// `Clone` trait defines the interface for cloning values.
pub trait Clone<T> {
    /// Takes a snapshot of a copyable value and returns a clone of that value.

T is not "copyable" here (if you mean a trait bound on +Copy)

Suggestion:

/// Returns a copy of the value.

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.

3 participants