-
Notifications
You must be signed in to change notification settings - Fork 15
feat!: reduce size of Id and add IdRef #31
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,6 +285,11 @@ pub enum TypeBindingKind { | |
Constraint(Vec<GenericBound>), | ||
} | ||
|
||
#[doc(hidden)] | ||
#[repr(transparent)] | ||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct IdType<T: ?Sized>(T); | ||
|
||
/// An opaque identifier for an item. | ||
/// | ||
/// It can be used to lookup in [`Crate::index`] or [`Crate::paths`] to resolve it | ||
|
@@ -296,11 +301,28 @@ pub enum TypeBindingKind { | |
/// Rustdoc makes no guarantees about the inner value of Id's. Applications | ||
/// should treat them as opaque keys to lookup items, and avoid attempting | ||
/// to parse them, or otherwise depend on any implementation details. | ||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
// FIXME(aDotInTheVoid): Consider making this non-public in rustdoc-types. | ||
pub struct Id(pub String); | ||
pub type Id = IdType<Box<str>>; | ||
|
||
/// A reference to an [`Id`] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But an Also, this doc comment should explain the motivations for doing this. |
||
pub type IdRef = IdType<str>; | ||
|
||
impl std::ops::Deref for Id { | ||
type Target = IdRef; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
let inner: &str = self.0.as_ref(); | ||
// Safety: &IdRef has the same layout and lifetime as &str due to the repr(transparent) | ||
unsafe { std::mem::transmute(inner) } | ||
} | ||
} | ||
|
||
impl std::borrow::Borrow<IdRef> for Id { | ||
fn borrow(&self) -> &IdRef { | ||
self | ||
} | ||
} | ||
|
||
/// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any aditional info. | ||
/// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any additional info. | ||
/// | ||
/// Part of [`ItemSummary`]. | ||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this? I think It'd be better to just duplicate all the derives, rather than using a type alias here.