Comments (2)
I really like this idea, especially the concept of "This way they don't have to think about how CompactStrings actually work. Things just work."
It's a bit of bikeshedding, but I'm not sure if we need to prefix try_new_inline(...)
with try_
, I think we can just name the API new_inline(...)
. For example, String::from_utf8(...)
is fallible but is not prefixed with try_
.
I would propose the following API:
impl CompactString {
pub fn new(s: impl AsRef<str>) -> Self { ... }
pub const new_const(s: &'static str) -> Self { ... }
/// ... include thorough documentation on why this method exists, similar to from_string_buffer()
pub const new_inline(s: &str) -> Result<Self, InlineError> { ... }
}
pub struct InlineError {
requested_size: usize,
}
This is a breaking change for new_inline(...)
, but based on semver it's okay to introduce breaking changes when going from 0.X
-> 0.Y
, so I would be okay with making this change
from compact_str.
- I would rename
from_static_str()
intoconst_new()
(borrowing the name e.g. from tokio), to make it obvious that this is the function one should use.
That seems to be a reasonable API, much better than panic on too large in new_inline()
.
- I would rename
new_inline()
intotry_new_inline()
and make this fallible.
Yeah I think that's more reasonable than implicit panic.
Users could still .unwrap()
it themselves if they want to, but that's explicit.
from compact_str.
Related Issues (20)
- `ToCompactString` formats twice HOT 6
- Fuzz Failure! 5628044824 HOT 1
- Fuzz Failure! 5630817545 HOT 1
- Support `no_std` HOT 1
- Reduce bus factor HOT 4
- Fuzz Failure! 6442422522 HOT 1
- perf: Re-enable specialization for String when castaway is updated
- docs: Document support for `from_static_str()` and `no_std`
- test: Update fuzzing harness to create a `CompactString` from a `&'static str`
- bug: Mutating underlying `&'static str` HOT 6
- Fuzz Failure! 6444883708 HOT 1
- feat: Implement traits for database crates HOT 1
- Safer Repr? HOT 6
- CompactString::as_mut_bytes returns a &mut reference to uninitialized bytes HOT 1
- Consider implementing From<CompactString> for std::error::Error HOT 3
- Typo Error
- Dual License with MIT and Apache 2.0 HOT 1
- Merge compact_bytes
- f64::to_compact_string differs from to_string HOT 2
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 compact_str.