2 releases

0.1.1 Feb 24, 2023
0.1.0 Feb 8, 2023

#554 in Concurrency

Download history 18/week @ 2024-02-25 1/week @ 2024-03-03 7/week @ 2024-03-10 1/week @ 2024-03-17 94/week @ 2024-03-24 60/week @ 2024-03-31 42/week @ 2024-04-07 19/week @ 2024-04-14 46/week @ 2024-04-21

256 downloads per month

MIT/Apache

81KB
1K SLoC

SwapArc

You can add SwapArc to your Cargo toml by copying this line: swap-arc = "0.1.0"

Note: This is basically a faster (only tested on multiple x86_64 setups) drop-in replacement for ArcSwap

SwapArc allows you to swap out Arcs while using them.
Let's consider this example:

use std::sync::Arc;
use std::thread;

struct Config {
    timout: u64,
    ...
}

struct Server {
    config: SwapArc<Config>,
    ...
}

fn test() {
    let server = Arc::new(Server {
        config: Config {
            timout: 1000,
            ...
        },
        ...
    });
    thread::spawn(|| {
        loop {
            // load the config without fearing any blocking or expensive operations.
            server.accept_connection(server.config.load().timeout);
        }
    });
    ...
}

// on network update, update the config seamlessly without blocking loads
server.config.update(Arc::new(Config {
    timeout: ...,
    ...
}));

Dependencies

~180–425KB