Giter VIP home page Giter VIP logo

Comments (3)

hdevalence avatar hdevalence commented on May 23, 2024

The Copy trait is a marker that the value can be duplicated by copying bits, whereas Clone can perform arbitrary logic (a "deep copy"). We require Copy because it doesn't really make sense to do constant-time operations on non-Copyable types.

Your example does use Copy, just not explicitly (e.g., in the line let t = mask & (*pi ^ *qi)).

As you note in the edit, the provided implementations are there for implementation convenience, but implementors can override them if they wish.

from subtle.

nickray avatar nickray commented on May 23, 2024

Yes, it's a marker trait, but it also (when implemented e.g. on newtypes) cause the compiler to change behaviour and implicitly copy things around, eliminating compile time checks. So not just "can" but also "does". (Yes, in my example copies are also done, but of individual entries, not the entire type.)

As noted, I assume all your current use cases that are Copy implement Clone also, in exactly the same way - no deep copy. Do they?

As it stands, I have the choice of making my types Copy or not using your library. Do you have some (heuristic...) argument on why I should do the former?

Also, do you foresee actual harm in replacing the Copy with a Clone bound (given it would trivially extend the applicability of the library)?

from subtle.

hdevalence avatar hdevalence commented on May 23, 2024

The heuristic reason why your types should be Copy is that constant-time operations implemented using bit operations should be performed on types which are bit-copyable.

You are of course free to not use this library if it doesn't suit your needs, but I don't think we will be relaxing the Copy bound.

from subtle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.