thomcc / arcstr

Better reference counted strings for Rust
Apache License 2.0
114 stars 18 forks source link

Add ArcStr::try_alloc to support fallible allocation #32

Closed thomcc closed 2 years ago

thomcc commented 2 years ago

The name is a bit dubious — arguably it should be try_new. I prefer this name, as it's very clear in which case it is that failure occurs.

That said, arguably it should still return a Result type, but I don't think it matters.

In particular: I don't really think it's worth exposing the distinction between the different allocation failures, as (technically) that could be used to argue changing the size of an ThinInner header in the future is breaking (as code that only handles one error might have to handle the other).

This also tells codecov it's not a big deal if coverage drops a little (which we used to do, but I guess the format of it's configuration changed? Who the hell knows).

This is kind of needed as I'm unsure how to artificially trigger this failure (the code is straightforward enough, though). If/when we support custom allocators (if an API for this ever stabilizes) testing that case will become more straightforward, as it could be done with a mocked allocator.

codecov-commenter commented 2 years ago

Codecov Report

Merging #32 (f80f573) into main (f5eed2a) will decrease coverage by 0.07%. The diff coverage is 64.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #32      +/-   ##
==========================================
- Coverage   96.51%   96.43%   -0.08%     
==========================================
  Files           6        6              
  Lines         860      869       +9     
==========================================
+ Hits          830      838       +8     
- Misses         30       31       +1     
Impacted Files Coverage Δ
src/arc_str.rs 92.24% <58.33%> (-0.19%) :arrow_down:
tests/arc_str.rs 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f5eed2a...f80f573. Read the comment docs.