yewstack / implicit-clone

Immutable types and ImplicitClone trait similar to Copy
20 stars 10 forks source link

Impl ImplicitClone for arrays and ref arrays #42

Closed cecton closed 1 year ago

cecton commented 1 year ago

Related to https://github.com/yewstack/yew-autoprops/pull/10

ranile commented 1 year ago

I don't think this clone should be implicit. [0; 1024] would implement ImplcitClone end up closing a kilobyte of data without the user explicitly instructing to do so

cecton commented 1 year ago

Yeah but [u8; 1024] is Copy already...

fn main() {
    fn copy<T: Copy>(x: T) -> T { x }
    let x: [u8; 1024] = todo!();
    copy(x);
}

It does compile.

kirillsemyonkin commented 1 year ago

fn copy(x: T) -> T { x }

Tip for this example lol, look at std::mem::copy, it does &T and *x

kirillsemyonkin commented 1 year ago

I don't think this clone should be implicit

Like @cecton mentioned, all Copy types should ideally be ImplicitClone (#32)

cecton commented 1 year ago

fn copy(x: T) -> T { x }

Tip for this example lol, look at std::mem::copy, it does &T and *x

good to know! I checked but it's on nightly at the moment... so I'll keep the small function for now I guess

cecton commented 1 year ago

I didn't want to push changes we don't all agree on so I reverted the changes on the tests and documentation and make a separate PR for those so we can merge already the small change of this PR which is adding arrays to the ImplicitClone family.

@hamza1311 are you okay with the argument provided for implementing ImplicitClone on arrays?

ranile commented 1 year ago

Yeah, I understand that argument. Feel free to merge it when you want to