• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: why does rust allow comparison between &String and string slice?

Resolved: why does rust allow comparison between &String and string slice?

0
By Isaac Tonny on 16/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve why does rust allow comparison between &String and string slice?

Question:

why does the above code work? how is rust compiler able to compare &String with a string slice?

Best Answer:

Because PartialEq<str> is implemented for String, so you can compare String with str, and there is a blanket implementation <A: PartialEq<B>> PartialEq<&B> for &A, so you can also compare &String with &str.
This is not related to deref coercion, as it does not apply to operators.

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

rust string
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Why when i change manualy the url on my react page it ignores the .css file?

24/03/2023

Resolved: navigate and redirect not redirecting to path in react router

24/03/2023

Resolved: Time Complexity: Find the number of people who know a secret leetcode 2327

24/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.