Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit a9f9cb9

Browse files
committed
deploy: 5da813a
0 parents  commit a9f9cb9

File tree

312 files changed

+42779
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

312 files changed

+42779
-0
lines changed

.lock

Whitespace-only changes.

.nojekyll

Whitespace-only changes.

cactusref/adopt/trait.Adopt.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta http-equiv="refresh" content="0;URL=../../cactusref/trait.Adopt.html">
5+
<title>Redirection</title>
6+
</head>
7+
<body>
8+
<p>Redirecting to <a href="../../cactusref/trait.Adopt.html">../../cactusref/trait.Adopt.html</a>...</p>
9+
<script>location.replace("../../cactusref/trait.Adopt.html" + location.search + location.hash);</script>
10+
</body>
11+
</html>

cactusref/all.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="List of all items in this crate"><title>List of all items in this crate</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="cactusref" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.0-nightly (b15a874aa 2025-11-02)" data-channel="nightly" data-search-js="search-5c29b3b5.js" data-stringdex-js="stringdex-c3e638e9.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod sys"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">All</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../cactusref/index.html">cactusref</a><span class="version">0.5.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h3><a href="#structs">Crate Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><h1>List of all items</h1><rustdoc-toolbar></rustdoc-toolbar></div><h3 id="structs">Structs</h3><ul class="all-items"><li><a href="struct.Rc.html">Rc</a></li><li><a href="struct.Weak.html">Weak</a></li></ul><h3 id="traits">Traits</h3><ul class="all-items"><li><a href="trait.Adopt.html">Adopt</a></li></ul><h3 id="types">Type Aliases</h3><ul class="all-items"><li><a href="type.CactusRef.html">CactusRef</a></li><li><a href="type.CactusWeakRef.html">CactusWeakRef</a></li></ul></section></div></main></body></html>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Examples of implementing self-referential data structures with CactusRef. `CactusRef` can be used to implement collections that own strong references to themselves."><title>cactusref::implementing_self_referential_data_structures - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="cactusref" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.0-nightly (b15a874aa 2025-11-02)" data-channel="nightly" data-search-js="search-5c29b3b5.js" data-stringdex-js="stringdex-c3e638e9.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Module implementing_self_referential_data_structures</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../cactusref/index.html">cactusref</a><span class="version">0.5.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module implementing_<wbr>self_<wbr>referential_<wbr>data_<wbr>structures</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#doubly-linked-list" title="Doubly-linked List">Doubly-linked List</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate cactusref</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">cactusref</a></div><h1>Module <span>implementing_<wbr>self_<wbr>referential_<wbr>data_<wbr>structures</span>&nbsp;<button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/cactusref/doc/implementing_self_referential_data_structures.rs.html#1-118">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Examples of implementing self-referential data structures with CactusRef.
2+
<code>CactusRef</code> can be used to implement collections that own strong references
3+
to themselves.</p>
4+
<h2 id="doubly-linked-list"><a class="doc-anchor" href="#doubly-linked-list">§</a>Doubly-linked List</h2>
5+
<p>The following implements a doubly-linked list that is fully deallocated once
6+
the <code>list</code> binding is dropped.</p>
7+
8+
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::cell::RefCell;
9+
<span class="kw">use </span>std::iter;
10+
11+
<span class="kw">use </span>cactusref::{Adopt, Rc};
12+
13+
<span class="kw">struct </span>Node&lt;T&gt; {
14+
<span class="kw">pub </span>prev: <span class="prelude-ty">Option</span>&lt;Rc&lt;RefCell&lt;<span class="self">Self</span>&gt;&gt;&gt;,
15+
<span class="kw">pub </span>next: <span class="prelude-ty">Option</span>&lt;Rc&lt;RefCell&lt;<span class="self">Self</span>&gt;&gt;&gt;,
16+
<span class="kw">pub </span>data: T,
17+
}
18+
19+
<span class="kw">struct </span>List&lt;T&gt; {
20+
<span class="kw">pub </span>head: <span class="prelude-ty">Option</span>&lt;Rc&lt;RefCell&lt;Node&lt;T&gt;&gt;&gt;&gt;,
21+
}
22+
23+
<span class="kw">impl</span>&lt;T&gt; List&lt;T&gt; {
24+
<span class="kw">fn </span>pop(<span class="kw-2">&amp;mut </span><span class="self">self</span>) -&gt; <span class="prelude-ty">Option</span>&lt;Rc&lt;RefCell&lt;Node&lt;T&gt;&gt;&gt;&gt; {
25+
<span class="kw">let </span>head = <span class="self">self</span>.head.take()<span class="question-mark">?</span>;
26+
<span class="kw">let </span>tail = head.borrow_mut().prev.take();
27+
<span class="kw">let </span>next = head.borrow_mut().next.take();
28+
<span class="kw">if let </span><span class="prelude-val">Some</span>(<span class="kw-2">ref </span>tail) = tail {
29+
Rc::unadopt(<span class="kw-2">&amp;</span>head, tail);
30+
Rc::unadopt(tail, <span class="kw-2">&amp;</span>head);
31+
32+
tail.borrow_mut().next.clone_from(<span class="kw-2">&amp;</span>next);
33+
<span class="kw">if let </span><span class="prelude-val">Some</span>(<span class="kw-2">ref </span>next) = next {
34+
<span class="kw">unsafe </span>{
35+
Rc::adopt_unchecked(tail, next);
36+
}
37+
}
38+
}
39+
<span class="kw">if let </span><span class="prelude-val">Some</span>(<span class="kw-2">ref </span>next) = next {
40+
Rc::unadopt(<span class="kw-2">&amp;</span>head, next);
41+
Rc::unadopt(next, <span class="kw-2">&amp;</span>head);
42+
43+
next.borrow_mut().prev.clone_from(<span class="kw-2">&amp;</span>tail);
44+
<span class="kw">if let </span><span class="prelude-val">Some</span>(<span class="kw-2">ref </span>tail) = tail {
45+
<span class="kw">unsafe </span>{
46+
Rc::adopt_unchecked(next, tail);
47+
}
48+
}
49+
}
50+
<span class="self">self</span>.head = next;
51+
<span class="prelude-val">Some</span>(head)
52+
}
53+
}
54+
55+
<span class="kw">impl</span>&lt;T&gt; From&lt;Vec&lt;T&gt;&gt; <span class="kw">for </span>List&lt;T&gt; {
56+
<span class="kw">fn </span>from(list: Vec&lt;T&gt;) -&gt; <span class="self">Self </span>{
57+
<span class="kw">let </span>nodes = list
58+
.into_iter()
59+
.map(|data| {
60+
Rc::new(RefCell::new(Node {
61+
prev: <span class="prelude-val">None</span>,
62+
next: <span class="prelude-val">None</span>,
63+
data,
64+
}))
65+
})
66+
.collect::&lt;Vec&lt;<span class="kw">_</span>&gt;&gt;();
67+
<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..nodes.len() - <span class="number">1 </span>{
68+
<span class="kw">let </span>curr = <span class="kw-2">&amp;</span>nodes[i];
69+
<span class="kw">let </span>next = <span class="kw-2">&amp;</span>nodes[i + <span class="number">1</span>];
70+
curr.borrow_mut().next = <span class="prelude-val">Some</span>(Rc::clone(next));
71+
next.borrow_mut().prev = <span class="prelude-val">Some</span>(Rc::clone(curr));
72+
<span class="kw">unsafe </span>{
73+
Rc::adopt_unchecked(curr, next);
74+
Rc::adopt_unchecked(next, curr);
75+
}
76+
}
77+
<span class="kw">let </span>tail = <span class="kw-2">&amp;</span>nodes[nodes.len() - <span class="number">1</span>];
78+
<span class="kw">let </span>head = <span class="kw-2">&amp;</span>nodes[<span class="number">0</span>];
79+
tail.borrow_mut().next = <span class="prelude-val">Some</span>(Rc::clone(head));
80+
head.borrow_mut().prev = <span class="prelude-val">Some</span>(Rc::clone(tail));
81+
<span class="kw">unsafe </span>{
82+
Rc::adopt_unchecked(tail, head);
83+
Rc::adopt_unchecked(head, tail);
84+
}
85+
86+
<span class="kw">let </span>head = Rc::clone(head);
87+
<span class="self">Self </span>{ head: <span class="prelude-val">Some</span>(head) }
88+
}
89+
}
90+
91+
<span class="kw">let </span>list = iter::repeat(())
92+
.map(|<span class="kw">_</span>| <span class="string">"a"</span>.repeat(<span class="number">1024 </span>* <span class="number">1024</span>))
93+
.take(<span class="number">10</span>)
94+
.collect::&lt;Vec&lt;<span class="kw">_</span>&gt;&gt;();
95+
<span class="kw">let </span><span class="kw-2">mut </span>list = List::from(list);
96+
97+
<span class="kw">let </span>head = list.pop().unwrap();
98+
<span class="macro">assert_eq!</span>(Rc::strong_count(<span class="kw-2">&amp;</span>head), <span class="number">1</span>);
99+
<span class="macro">assert!</span>(head.borrow().data.starts_with(<span class="string">'a'</span>));
100+
101+
<span class="comment">// The new head of the list is owned three times:
102+
//
103+
// - itself.
104+
// - the `prev` pointer to it from it's next element.
105+
// - the `next` pointer from the list's tail.
106+
</span><span class="macro">assert_eq!</span>(list.head.as_ref().map(Rc::strong_count), <span class="prelude-val">Some</span>(<span class="number">3</span>));
107+
108+
<span class="comment">// The popped head is no longer part of the graph and can be safely dropped
109+
// and deallocated.
110+
</span><span class="kw">let </span>weak = Rc::downgrade(<span class="kw-2">&amp;</span>head);
111+
drop(head);
112+
<span class="macro">assert!</span>(weak.upgrade().is_none());
113+
114+
drop(list);
115+
<span class="comment">// all memory consumed by the list nodes is reclaimed.</span></code></pre></div></div></details></section></div></main></body></html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window.SIDEBAR_ITEMS = {};

0 commit comments

Comments
 (0)