Giter VIP home page Giter VIP logo

Comments (5)

ebfull avatar ebfull commented on May 25, 2024 1

generic-impls (as implemented) violates an invariant that Rust features are supposed to preserve: enabling a feature is reverse compatible with disabling it, so the API must not change. This contradicts impl<T> Trait for T impls for e.g. ConditionallyAssignable; when generic-impls is enabled the orphan rules will suddenly make a separate crate in your dependency tree fail to compile if it has an implementation of the trait.

As far as I can tell, you can provide a simple API like this:

trait ConditionallySelectable {
    fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self;
    
    // Provided impls:
    fn conditional_swap(&mut self, other: &mut Self, choice: Choice)
        where Self: Copy
    {
        // ...
    }
    
    fn conditional_assign(&mut self, other: &Self, choice: Choice)
    {
        // ...
    }
    
    fn conditional_negate(&mut self, choice: Choice)
        where for<'a> &'a Self: Neg<Output = Self>
    {
        // ...
    }
}

If people want to overload the provided impls for performance optimizations they can do so, or if they want to do something exotic they can make a subtrait or something.

from subtle.

hdevalence avatar hdevalence commented on May 25, 2024

No need to apologize for filing issues, they're good issues!

Your comment #24 (comment) seems relevant to this one too, linking to it so it's cross-referenced.

from subtle.

hdevalence avatar hdevalence commented on May 25, 2024

Hmm, I'm not exactly sure I understand what's happening here.

First, there's a Copy bound in play (cf your #23). It does seem unnecessary. Would this be simplified at all if it weren't required?

When you implement ConditionallySelectable, why do you need to provide a conditional impl of ConditionallySwappable? If you enable the generic impls feature when you compile subtle, that impl should be provided for you, right? So I'm not sure I understand why you couldn't specify that subtle feature (I think it's the default?) unconditionally, rather than provide a fallback impl gated by your own mirror feature.

from subtle.

Pratyush avatar Pratyush commented on May 25, 2024
  1. That Copy bound is unnecessary only for the generic impl of ConditionallyAssignable; generically impl'ing ConditionallySwappable seems to require making a temporary copy of one of the inputs, and so requires Copy (or perhaps some trickery with unsafe stuff).

  2. I need to provide a conditional impl because whenever Thing is Copy, my unconditional impl would conflict with the one provided in subtle under generic-impls. Hence rustc disallows the blanket impl for Thing.

from subtle.

isislovecruft avatar isislovecruft commented on May 25, 2024

This should be fixed by #29.

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.