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

Allow concatenation of different array strings #269

Closed
wants to merge 1 commit into from

Conversation

Callum-A
Copy link

As a user I would like to concat two ArrayString easily. This exposes two methods to do this.

/// assert_eq!(&string[..], "ab");
/// ```
#[track_caller]
pub fn push_array_string<const OTHER_CAP: usize>(&mut self, other: ArrayString<OTHER_CAP>) {
Copy link
Owner

Choose a reason for hiding this comment

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

The user should just use string.push_str(&a) here. Is there a reason not to do that?

Copy link
Author

Choose a reason for hiding this comment

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

Ah would this work? I actually didn't know that! I assume this would also avoid heap allocs?

Copy link
Owner

Choose a reason for hiding this comment

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

of course, no heap allocations extra. ArrayString is just like another kind of String - they both have zero cost deref to &str.

Copy link
Author

Choose a reason for hiding this comment

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

Ah perfect this can likely get closed out then!

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, feel free to add an example that shows how this works, if you want to.

@bluss
Copy link
Owner

bluss commented Aug 17, 2024

Closing as the use case is already served by .push_str(&x).

@bluss bluss closed this Aug 17, 2024
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