Skip to content
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

Use Into<String> instead of ToString #2127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RReverser
Copy link
Member

@RReverser RReverser commented Jan 15, 2025

Description of Changes

As discussed on #2118, ToString is overly generic because it includes any type that implements Display.

Instead, we only want to accept string-like types (whether owned or not), which is better covered by Into.

API and ABI breaking changes

If this is an API or ABI breaking change, please apply the
corresponding GitHub label.

Expected complexity level and risk

2

How complicated do you think these changes are? Grade on a scale from 1 to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex change.

This complexity rating applies not only to the complexity apparent in the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning ways.

Testing

Describe any testing you've done, and any testing you'd like your reviewers to do,
so that you're confident that all the changes work as expected!

  • Ran CI tests, internal tests failed, fixed them.

As discussed on #2118, ToString is overly generic because it includes any type that implements Display.

Instead, we only want to accept string-like types (whether owned or not), which is better covered by Into<String>.
@RReverser RReverser requested a review from gefjon January 15, 2025 14:06
@RReverser RReverser added the api-break A PR that makes an API breaking change label Jan 15, 2025
Comment on lines +39 to +49
impl<const N: usize> From<&'_ HexString<N>> for String {
fn from(hex: &HexString<N>) -> Self {
hex.as_str().into()
}
}

impl<const N: usize> From<HexString<N>> for String {
fn from(hex: HexString<N>) -> Self {
hex.as_str().into()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these impls necessary? Where are they used?

Copy link
Member Author

Choose a reason for hiding this comment

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

Internal tests pass hex strings to these APIs and fail without those impls.

@gefjon
Copy link
Contributor

gefjon commented Jan 15, 2025

How confident are you that our existing demos (I believe this is just quickstart-chat) do not depend on the previous behavior? What about external customers' code? What is the list of string-like types that implement Into<String> which you believe we want to allow? Are there any types which are ToString but not Into<String> which you think our customers may try to pass to these methods?

I can answer all of these questions, but it is not my job as reviewer to do so, it is your job as PR author. The answers should be recorded in your PR description for posterity.

@RReverser
Copy link
Member Author

RReverser commented Jan 15, 2025

How confident are you that our existing demos (I believe this is just quickstart-chat) do not depend on the previous behavior?

I'm not, at all. I just offered a comment on the previous PR and you said you'd accept a followup PR changing those APIs. If there is no interest in changing them after all, feel free to close it.

I'd argue it shouldn't be my job as a reviewer to issue followup PRs changing used traits either, since I'm working on other stuff, but here we are :)

@bfops bfops added breaks library compatibility This change breaks the SpacetimeDB library interface release-any To be landed in any release window labels Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-break A PR that makes an API breaking change breaks library compatibility This change breaks the SpacetimeDB library interface release-any To be landed in any release window
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants