Skip to content

Conversation

@danielthank
Copy link

deref() returns &Target

pub trait Deref {
    type Target: ?Sized;

    // Required method
    fn deref(&self) -> &Self::Target;
}

So Target should be str instead of &str for String type

Deref trait source code: https://doc.rust-lang.org/src/core/ops/deref.rs.html#139-151
String implementation source code: https://doc.rust-lang.org/src/alloc/string.rs.html#2722-2730

@danielthank danielthank changed the title Fix String implementation of Deref explanation Fix String implementation for Deref explanation Nov 10, 2025
@YHTerrance YHTerrance self-requested a review November 11, 2025 03:35
Copy link
Contributor

@YHTerrance YHTerrance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks for the correction.

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.

2 participants