Title: Theory / Unimportant / CS / Programming / Rust / Library / Pointer / RC

Name: Rc
Definition: A smart pointer allowing multiple owneship. When no owner remains, the content is dropped
Page: https://doc.rust-lang.org/book/ch15-03-drop.html
Chapter: 15
Context: Rust
Etymology: Reference counted

Instruction: Rc::new(v)
Page: https://doc.rust-lang.org/book/ch15-03-drop.html
Effect: Put v in heap
Language: Rust
Chapter: 15
Returns: A Rc pointer to v

Instruction: Rc::clone(v)
Page: https://doc.rust-lang.org/book/ch15-03-drop.html
Language: Rust
Chapter: 15
Returns: Another rc pointer to v
Variables: v a Rc pointer

Instruction: v.strong_count()
Page: https://doc.rust-lang.org/book/ch15-04-rc.html
Language: Rust
Chapter: 15
Returns: Number of Rc pointers to v
Variables: v: RC<T>/weak<T>
Name: Rc

Question: What is important when using RC
Answer: Ensuring that there is no cycles leading to memory leak
Page: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
Chapter: 15
Context: Rust

Instruction: Rc::downgrade(r)
Page: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
Language: Rust
Chapter: 15
Returns: A Weak<T> pointing weakly to r
Variables: r a Rc<T>

Typ: Weak<T>
Meaning: A reference to a value of type T without ownership
Page: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
Language: Rust
Chapter: 15

Instruction: w.upgrade()
Page: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
Language: Rust
Chapter: 15
Returns: A Rc<T> if the reference still exists, None otherwise
Variables: w: Weak<T>

Instruction: r.weak_count()
Page: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
Language: Rust
Chapter: 15
Returns: Number of weak reference to r
Variables: v: RC<T>/weak<T>

Name: Arc<T>
Definition: A Rc<T> that is safe to share accross thread, ensuring atomic operations
Page: https://doc.rust-lang.org/book/ch16-03-shared-state.html
Chapter: 16
Context: Rust
Etymology: Atomic Rc<T>

Instruction: weak.as_ptr()
Page: https://doc.rust-lang.org/stable/std/rc/struct.Weak.html
Returns: a raw pointer to the object T pointed to by this weak
Variables: weak : Weak<T>

Instruction: rc.into_raw()
Page: https://doc.rust-lang.org/stable/std/rc/struct.Weak.html
Returns: consume pointer and turn it into a raw pointer
Variables: rc : Weak<T>/RC<T>

Instruction: Weak.from_raw(t_raw_pointer)
Page: https://doc.rust-lang.org/stable/std/rc/struct.Weak.html
Returns: create a weak pointer from a raw pointer

Instruction: weak.upgrade()
Page: https://doc.rust-lang.org/stable/std/rc/struct.Weak.html
Returns: Option to the RC contained in weak
Variables: weak : Weak<T>

Instruction: weak.ptr_eq(other)
Page: https://doc.rust-lang.org/stable/std/rc/struct.Weak.html
Returns: Whether both points to nothing or to the same thing
Variables: weak : Weak<T>

Instruction: rc.new_cyclic(fn)
Page: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html
Returns: A RC to the result of fn(weak), with weak a weak pointer to the same RC
Variables: rc: RC<T>

Instruction: rc.pin()
Page: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html
Returns: Same value, pinned
Variables: rc: RC<T>

Instruction: rc.try_unwrap()
Page: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html
Returns: The value if it was the last pointer, or the rc pointer otherwise
Variables: rc: RC<T>

Instruction: rc.(in|de)cremente_(weak|strong)_count()
Page: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html
Effect: Increment/decrement the weak/strong counter of this pointer
Variables: rc: RC<T>
Assuming: Value remains non-negative

Instruction: rc.get_mut()
Page: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html
Returns: None if value is shared. Otherwise, borrow the value in a mutable reference
Variables: rc: RC<T>

Instruction: rc.ptr_eq(other)
Page: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html
Returns: Whether both rc points to the same value
Variables: rc: RC<T>

Instruction: rc.make_mut()
Page: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html
Returns: Mutable rc to the same value. Cloned if another strong pointer to this value exists. Weak pointer gets disassociated if so
Variables: rc: RC<T>

Instruction: rc.dowcast::<U>()
Page: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html
Returns: A rc to same value, as type U, if possible. Original value in case of failure
Variables: rc: RC<T>

Instruction: rc.as_ref()
rc.borrow()
Page: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html
Returns: A shared reference to value owned here
Variables: rc: RC<T>