Comments (5)
I'd say [u8]
should be the main type to talk about here, since Vec<u8>
derefs to it.
(But the &[u8]
syntax may not have been meant literally, as BStr
is a newtype around [u8]
, not around a reference)
And, yeah, I'd be fine with BStr
that derefs to [u8]
, since I'd prefer having most of the functionality in libcore, and just get e.g. the debug formatting from this crate.
from bstr.
from bstr.
One little hiccup that I've run into is that a lot of the current BStr
APIs accept anything that implements AsRef<[u8]>
. So that means you can use somebstr.find("foo")
or somebstr.find(b"foo")
, which is nice for ergonomics. I can continue to do this for the extension trait APIs of course, but with an extension trait, there are several methods already defined on slices that we wouldn't want to redefine. For example, there are already starts_with
and ends_with
methods defined on &[u8]
, but their only valid parameter is &[u8]
which means somebstr.starts_with("foo")
won't work. I see a few choices here, all of which kind of suck honestly:
- Don't define methods like
starts_with
that already exist and keep theAsRef<[u8]>
for APIs we do define. We live with the inconsistency. (Users will invariably ask, "why do some methods accept a&str
but others don't?!") - When there are conflicting methods, like
starts_with
, provide "str" focused variants, e.g.,starts_with_str
andends_with_str
. - When there are conflicting methods, define new methods with the same name and require users to disambiguate methods via UFCS. (Yuck. Only listed for completeness.)
- Get rid of the
AsRef<[u8]>
convenience on all APIs and make everything accept a concrete&[u8]
in order to be consistent. This is kind of a bummer, since then you can't just write,somebstr.find("☃☃☃")
, but instead must writesomebstr.find("☃☃☃".as_bytes())
.
Any thoughts on what the preferred route ought to be?
from bstr.
I like the second option personally
from bstr.
@lespea Could you elaborate a bit more? :)
from bstr.
Related Issues (20)
- Character-oriented slicing and length APIs HOT 2
- Consider using `once_cell` instead of `lazy_static` HOT 3
- Ensure crate abides by the Unicode Data Files and Software License HOT 4
- bstr pulls in serde when `serde` feature is not specified HOT 6
- bstr-bench Cargo.lock out of sync
- Can the MSRV be lowered to 1.57 (or lower)? HOT 3
- Clarify None case in bstr::decode_utf8 HOT 1
- Feature request: `impl Deserialize for Box<BStr>`
- bstr 1.3.0 with `impl AsRef<BStr> for BStr` breaks some folks downstream HOT 1
- candidate versions found which didn't match: 0.2.17, 0.2.16, 0.2.15, ... HOT 5
- Possible panic safety issues in insert_str HOT 2
- Complementary ByteSlice functions addition - find_not_byte / rfind_not_byte HOT 1
- Use clippy in CI? HOT 2
- Intradoc links are broken when building with no default features HOT 3
- re-enable miri tests
- Accept array of str for split_str HOT 1
- remove `Borrow<BStr> for String` impls (and similar) in a semver compatible release HOT 9
- Add unescape_ascii fn HOT 4
- Display implementation doesn't respect Formatter options
- `bstr::Split` should implement clone. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bstr.