Mention that unsized types are not supported, maybe explain why
shepmaster opened this issue · 4 comments
shepmaster commented
use arc_swap::ArcSwap; // 0.4.4
fn sized(_: ArcSwap<u8>) {} // OK
fn not_sized(_: ArcSwap<[u8]>) {}
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src/lib.rs:5:1
|
5 | fn not_sized(_: ArcSwap<[u8]>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `[u8]`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required because of the requirements on the impl of `arc_swap::ref_cnt::RefCnt` for `std::sync::Arc<[u8]>`
= note: required by `arc_swap::ArcSwapAny`
vorner commented
Good point. I'll try to squeeze it into the documentation while not overloading the reader with too much information.
It's due to technical limitations ‒ such pointers are fat and can't be fed into AtomicPtr
.
NobodyXu commented
It is actually possible to do so using triomphe::ThinArc
with feature arc-swap
enabled.
vorner commented
Thanks for finding that one out. It's still a bit of cheating that can't be used everywhere (I think this works for variable-sized slices, but not for trait objects, am I right?), but worth mentioning in the relevant chapter ‒ I've updated it. I'll piggy-back it with the next release.
NobodyXu commented
I think this works for variable-sized slices, but not for trait objects, am I right?
Yes that’s correct.