Skip to content

Commit

Permalink
deploy: 3d7df4b
Browse files Browse the repository at this point in the history
  • Loading branch information
artichoke-ci committed Dec 24, 2024
0 parents commit 288645d
Show file tree
Hide file tree
Showing 259 changed files with 67,844 additions and 0 deletions.
Empty file added .lock
Empty file.
Empty file added .nojekyll
Empty file.
11 changes: 11 additions & 0 deletions cactusref/adopt/trait.Adopt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../cactusref/trait.Adopt.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../cactusref/trait.Adopt.html">../../cactusref/trait.Adopt.html</a>...</p>
<script>location.replace("../../cactusref/trait.Adopt.html" + location.search + location.hash);</script>
</body>
</html>
1 change: 1 addition & 0 deletions cactusref/all.html
Original file line number Diff line number Diff line change
@@ -0,0 +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-Regular-0fe48ade.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" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-46132b98.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.85.0-nightly (426d17342 2024-12-21)" data-channel="nightly" data-search-js="search-036cda7a.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><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"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><h1>List of all items</h1><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>
116 changes: 116 additions & 0 deletions cactusref/implementing_self_referential_data_structures/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<!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-Regular-0fe48ade.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" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-46132b98.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.85.0-nightly (426d17342 2024-12-21)" data-channel="nightly" data-search-js="search-036cda7a.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><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"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">cactusref</a></span><h1>Module <span>implementing_self_referential_data_structures</span><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.
<code>CactusRef</code> can be used to implement collections that own strong references
to themselves.</p>
<h2 id="doubly-linked-list"><a class="doc-anchor" href="#doubly-linked-list">§</a>Doubly-linked List</h2>
<p>The following implements a doubly-linked list that is fully deallocated once
the <code>list</code> binding is dropped.</p>

<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::cell::RefCell;
<span class="kw">use </span>std::iter;

<span class="kw">use </span>cactusref::{Adopt, Rc};

<span class="kw">struct </span>Node&lt;T&gt; {
<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;,
<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;,
<span class="kw">pub </span>data: T,
}

<span class="kw">struct </span>List&lt;T&gt; {
<span class="kw">pub </span>head: <span class="prelude-ty">Option</span>&lt;Rc&lt;RefCell&lt;Node&lt;T&gt;&gt;&gt;&gt;,
}

<span class="kw">impl</span>&lt;T&gt; List&lt;T&gt; {
<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; {
<span class="kw">let </span>head = <span class="self">self</span>.head.take()<span class="question-mark">?</span>;
<span class="kw">let </span>tail = head.borrow_mut().prev.take();
<span class="kw">let </span>next = head.borrow_mut().next.take();
<span class="kw">if let </span><span class="prelude-val">Some</span>(<span class="kw-2">ref </span>tail) = tail {
Rc::unadopt(<span class="kw-2">&amp;</span>head, tail);
Rc::unadopt(tail, <span class="kw-2">&amp;</span>head);

tail.borrow_mut().next.clone_from(<span class="kw-2">&amp;</span>next);
<span class="kw">if let </span><span class="prelude-val">Some</span>(<span class="kw-2">ref </span>next) = next {
<span class="kw">unsafe </span>{
Rc::adopt_unchecked(tail, next);
}
}
}
<span class="kw">if let </span><span class="prelude-val">Some</span>(<span class="kw-2">ref </span>next) = next {
Rc::unadopt(<span class="kw-2">&amp;</span>head, next);
Rc::unadopt(next, <span class="kw-2">&amp;</span>head);

next.borrow_mut().prev.clone_from(<span class="kw-2">&amp;</span>tail);
<span class="kw">if let </span><span class="prelude-val">Some</span>(<span class="kw-2">ref </span>tail) = tail {
<span class="kw">unsafe </span>{
Rc::adopt_unchecked(next, tail);
}
}
}
<span class="self">self</span>.head = next;
<span class="prelude-val">Some</span>(head)
}
}

<span class="kw">impl</span>&lt;T&gt; From&lt;Vec&lt;T&gt;&gt; <span class="kw">for </span>List&lt;T&gt; {
<span class="kw">fn </span>from(list: Vec&lt;T&gt;) -&gt; <span class="self">Self </span>{
<span class="kw">let </span>nodes = list
.into_iter()
.map(|data| {
Rc::new(RefCell::new(Node {
prev: <span class="prelude-val">None</span>,
next: <span class="prelude-val">None</span>,
data,
}))
})
.collect::&lt;Vec&lt;<span class="kw">_</span>&gt;&gt;();
<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..nodes.len() - <span class="number">1 </span>{
<span class="kw">let </span>curr = <span class="kw-2">&amp;</span>nodes[i];
<span class="kw">let </span>next = <span class="kw-2">&amp;</span>nodes[i + <span class="number">1</span>];
curr.borrow_mut().next = <span class="prelude-val">Some</span>(Rc::clone(next));
next.borrow_mut().prev = <span class="prelude-val">Some</span>(Rc::clone(curr));
<span class="kw">unsafe </span>{
Rc::adopt_unchecked(curr, next);
Rc::adopt_unchecked(next, curr);
}
}
<span class="kw">let </span>tail = <span class="kw-2">&amp;</span>nodes[nodes.len() - <span class="number">1</span>];
<span class="kw">let </span>head = <span class="kw-2">&amp;</span>nodes[<span class="number">0</span>];
tail.borrow_mut().next = <span class="prelude-val">Some</span>(Rc::clone(head));
head.borrow_mut().prev = <span class="prelude-val">Some</span>(Rc::clone(tail));
<span class="kw">unsafe </span>{
Rc::adopt_unchecked(tail, head);
Rc::adopt_unchecked(head, tail);
}

<span class="kw">let </span>head = Rc::clone(head);
<span class="self">Self </span>{ head: <span class="prelude-val">Some</span>(head) }
}
}

<span class="kw">let </span>list = iter::repeat(())
.map(|<span class="kw">_</span>| <span class="string">"a"</span>.repeat(<span class="number">1024 </span>* <span class="number">1024</span>))
.take(<span class="number">10</span>)
.collect::&lt;Vec&lt;<span class="kw">_</span>&gt;&gt;();
<span class="kw">let </span><span class="kw-2">mut </span>list = List::from(list);

<span class="kw">let </span>head = list.pop().unwrap();
<span class="macro">assert_eq!</span>(Rc::strong_count(<span class="kw-2">&amp;</span>head), <span class="number">1</span>);
<span class="macro">assert!</span>(head.borrow().data.starts_with(<span class="string">'a'</span>));

<span class="comment">// The new head of the list is owned three times:
//
// - itself.
// - the `prev` pointer to it from it's next element.
// - the `next` pointer from the list's tail.
</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>));

<span class="comment">// The popped head is no longer part of the graph and can be safely dropped
// and deallocated.
</span><span class="kw">let </span>weak = Rc::downgrade(<span class="kw-2">&amp;</span>head);
drop(head);
<span class="macro">assert!</span>(weak.upgrade().is_none());

drop(list);
<span class="comment">// all memory consumed by the list nodes is reclaimed.</span></code></pre></div>
</div></details></section></div></main></body></html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {};
Loading

0 comments on commit 288645d

Please sign in to comment.