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

Simplify instantiation of &BStr #110

Closed
Byron opened this issue Jul 9, 2022 · 3 comments
Closed

Simplify instantiation of &BStr #110

Byron opened this issue Jul 9, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@Byron
Copy link
Contributor

Byron commented Jul 9, 2022

This issue was spun off from this comment which states problems with creating instances of &BStr if type-inference bails out. The latter is typical within Cow and as one side of assert_eq!().

The intuitive way of doing this to me was BStr::new("") or BStr::new("hello") or BStr::new(b"hi"), similar to what's possible with std::path::Path::new(…).

@BurntSushi
Copy link
Owner

Aye. Were there any other helper functions you defined? I think it would be helpful to see those and see if we can bring them into bstr.

@Byron
Copy link
Contributor Author

Byron commented Jul 9, 2022

I am not sure about that 😅, as for no particular reason other than some familiarity I used fn b(s: impl AsRef<[u8]>) -> &BStr { s.into() }.

@BurntSushi
Copy link
Owner

Ah yeah. I wasn't sure if you had helpers for things other than construction.

BurntSushi added a commit that referenced this issue Jul 11, 2022
This adds a convenience constructor for building a BStr slice directly
from anything that impls AsRef<[u8]>. This is analogous to, e.g.,
Path::new from std.

While this constructor is redundant, it is often convenient because of
its concreteness. Alternatives rely on generics via trait impls, which
don't always work seamlessly.

Closes #110
@BurntSushi BurntSushi added the enhancement New feature or request label Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants