eater_arc_illegal

Struct ArcIllegal

Source
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>

Source

pub fn new(inner: T) -> ArcIllegal<T>

Creates a new ArcIllegal for given object

Source

pub fn as_ptr(&self) -> *mut T

Returns the raw pointer of the value

Source

pub fn ref_count(&self) -> usize

Return the amount of references that hold this object

Source

pub fn weak_ref_count(&self) -> usize

Return the amount of weak references that hold this object

Source

pub fn strong_ref_count(&self) -> usize

Return the amount of “strong” references that hold this object

Source

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);
}
Source

pub fn weak(&self) -> WeakIllegal<T>

Get a Weak reference to the value inside the IllegalArc

Source

pub fn dismantle(self) -> Result<T, Self>

If we’re the only reference, destroy it and give the object back as owned

Source

pub fn dismantle_with_weak(self) -> Result<T, Self>

Trait Implementations§

Source§

impl<T> Clone for ArcIllegal<T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for ArcIllegal<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for ArcIllegal<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T> DerefMut for ArcIllegal<T>

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<T: Display> Display for ArcIllegal<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for ArcIllegal<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Send for ArcIllegal<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.