pub struct ArcIllegal<T> { /* private fields */ }
Expand description
ArcIllegal is an Arc that’s illegal
ArcIllegal can always use it’s contents as mutable, it sounds unsafe and is unsafe too, but now without unsafe code blocks (they’re just hidden in this lib), because that’s what we’re Measuring these days
use eater_arc_illegal::ArcIllegal;
use std::time::Duration;
use std::thread::{spawn, sleep};
let mut x = ArcIllegal::new("hewwo".to_string());
let mut y = x.clone();
let mut z = y.dup();
let a = &mut *x;
let b = &mut *y.dup();
let c = &mut *z.dup();
c.push_str(" wo");
b.push_str("rl");
a.push_str("d!");
y.push_str(" :)");
let mut zz = z.dup();
spawn(move || {
z.push_str(" :OOO");
});
spawn(move || {
zz.push_str("race!!!");
});
println!("{}", a);
delay(Duration::from_millis(50));
println!("{}", a);
Implementations§
Source§impl<T> ArcIllegal<T>
impl<T> ArcIllegal<T>
Sourcepub fn new(inner: T) -> ArcIllegal<T>
pub fn new(inner: T) -> ArcIllegal<T>
Creates a new ArcIllegal for given object
Sourcepub fn weak_ref_count(&self) -> usize
pub fn weak_ref_count(&self) -> usize
Return the amount of weak references that hold this object
Sourcepub fn strong_ref_count(&self) -> usize
pub fn strong_ref_count(&self) -> usize
Return the amount of “strong” references that hold this object
Sourcepub fn dup(&self) -> Self
pub fn dup(&self) -> Self
Clones the ArcIllegal, convenience function for when the held type can be cloned
Examples found in repository?
examples/thread_num.rs (line 5)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let mut shared_num = arc(4);
let mut cloned = shared_num.dup();
*shared_num += 2;
std::thread::spawn(move || {
*cloned += 2;
});
std::thread::sleep(std::time::Duration::from_secs(1));
assert_eq!(8, *shared_num);
}
Sourcepub fn weak(&self) -> WeakIllegal<T>
pub fn weak(&self) -> WeakIllegal<T>
Get a Weak reference to the value inside the IllegalArc
Sourcepub fn dismantle(self) -> Result<T, Self>
pub fn dismantle(self) -> Result<T, Self>
If we’re the only reference, destroy it and give the object back as owned
pub fn dismantle_with_weak(self) -> Result<T, Self>
Trait Implementations§
Source§impl<T> Clone for ArcIllegal<T>
impl<T> Clone for ArcIllegal<T>
Source§impl<T: Debug> Debug for ArcIllegal<T>
impl<T: Debug> Debug for ArcIllegal<T>
Source§impl<T> Deref for ArcIllegal<T>
impl<T> Deref for ArcIllegal<T>
Source§impl<T> DerefMut for ArcIllegal<T>
impl<T> DerefMut for ArcIllegal<T>
Source§impl<T: Display> Display for ArcIllegal<T>
impl<T: Display> Display for ArcIllegal<T>
Source§impl<T> Drop for ArcIllegal<T>
impl<T> Drop for ArcIllegal<T>
impl<T> Send for ArcIllegal<T>
impl<T> Sync for ArcIllegal<T>
Auto Trait Implementations§
impl<T> Freeze for ArcIllegal<T>
impl<T> RefUnwindSafe for ArcIllegal<T>where
T: RefUnwindSafe,
impl<T> Unpin for ArcIllegal<T>
impl<T> UnwindSafe for ArcIllegal<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)