swapper 0.1.0

Swap ownership between threads
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented1 out of 5 items with examples
  • Size
  • Source code size: 24.85 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.62 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • asajeffrey/swapper
    2 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • github:servo:cargo-publish asajeffrey

swapper

Swap ownership of data between threads in Rust.

This crate allows threads to swap ownership of data without a transitory state where the thread owns nothing.

   let (ab, ba) = swapper::swapper();
   thread::spawn(move || {
      let mut a = String::from("hello");
      ab.swap(&mut a).unwrap();
      assert_eq!(a, "world");
   });
   let mut b = String::from("world");
   ba.swap(&mut b).unwrap();
   assert_eq!(b, "hello");