Skip to content

feat: Add IntoOwned trait#597

Merged
devongovett merged 28 commits intoparcel-bundler:masterfrom
kdy1:owned-trait
Oct 9, 2023
Merged

feat: Add IntoOwned trait#597
devongovett merged 28 commits intoparcel-bundler:masterfrom
kdy1:owned-trait

Conversation

@kdy1
Copy link
Contributor

@kdy1 kdy1 commented Oct 6, 2023

Closes #596

The signature should be

pub trait IntoOwned<'any> {
  type Owned: 'any;

  /// Make lifetime of `self` `'static`.
  fn into_owned(self) -> Self::Owned;
}

Description

  • The caller determines the trait to call, so the lifetime 'any of IntoOwned<'any> is determined by the caller.

This is identical as fn into_owned<'x>(self) -> Self<'x>.

  • The trait is implemented for nodes with any lifetime (not 'any), so it can be called if self is provided.

  • The bound for generics is for<'aa> T: IntoOwned<'aa>, so the implementation of generic parameters do not matter.

@kdy1 kdy1 changed the title feat: Add IntoOwned feat: Add IntoOwned trait Oct 6, 2023
@kdy1 kdy1 marked this pull request as ready for review October 6, 2023 06:24
@kdy1
Copy link
Contributor Author

kdy1 commented Oct 6, 2023

@devongovett I did it 😄

The code is not clean, though.

@kdy1
Copy link
Contributor Author

kdy1 commented Oct 6, 2023

Feel free to modify docs or codes 👍

@devongovett
Copy link
Member

Thanks, this looks good. I'll play around with it in more detail tomorrow.

lightningcss_derive is only really intended to be used by lightningcss itself and not by other crates, so just use `crate` to refer to it.
@devongovett devongovett merged commit 6a5ad49 into parcel-bundler:master Oct 9, 2023
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.

IntoOwned as a trait, and implement it for nodes when R implements IntoOwned

2 participants