thomcc / arcstr

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

Atomic swap? #30

Closed SOF3 closed 5 months ago

SOF3 commented 3 years ago

I would like to update an ArcStr atomically. Is it possible to implement some wrapper like arc_swap for arcstr, or must that introduce significant overhead?

SOF3 commented 3 years ago

It seems that we can make arcstr have an optional feature arc-swap that implements the arc_swap::RefCnt trait, and ArcSwapAny<ArcStr> can immediately work.

I can try to implement this if the proposal is approved.

thomcc commented 3 years ago

Yeah, that would be fine, since they seem fairly semver-stable. If there are issues I can take a stab at it as well.

thomcc commented 3 years ago

The feature should be called arc_swap though, e.g. it should just be

[dependencies]
arc_swap = { version = "1", optional = true }

Also you should note in the docs for this feature it should mention that turning this feature on requires libstd (arc_swap is not no_std).

SOF3 commented 3 years ago

The package name is arc-swap nor arc_swap.

SOF3 commented 3 years ago

Sorry, it appears that arc-swap does not really support fat pointers, and using ArcSwapAny<ArcStr> is not really fasible.

thomcc commented 3 years ago

Sorry, it appears that arc-swap does not really support fat pointers, and using ArcSwapAny is not really fasible.

Hm, Worth noting that only the pointee is fat, ArcStr itself is not. But maybe they don't handle that possibility.

When I have time I'll read up on the algorithm and see if its feasible to implement a less-involved version (likely less performant too, unless the fact that we have no weak or mutable data can be leveraged) of it behind a feature or something.

thomcc commented 5 months ago

It's not clear that I can integrate with the ArcSwap crate. It doesn't seem so, since the pointee being fat would IIUC be a problem.

Feel free to reopen if this is mistaken.