-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
/**/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[workspace] | ||
members = [ | ||
"ownership", | ||
"double-free", | ||
"borrow", | ||
"naive-borrow", | ||
"sneaky-borrow", | ||
"sneaky-borrow-with-lifetime", | ||
"concurrent-arc", | ||
"concurrent-arc-mutex", | ||
"concurrent-rc", | ||
"concurrent-rc-in-arc" | ||
] | ||
resolver = "2" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Rust: An Introduction | ||
--------------------- | ||
|
||
An introductory presentation of the Rust programming language, primarily focused | ||
on fostering internal interest and engagement. The focus of the Rust is memory | ||
safety, arguably its most distinctive, novel, and powerful feature. | ||
|
||
The presentation is made with [reveal.js](https://revealjs.com/), and is located | ||
in [docs](/docs). The original script on which the presentation | ||
is based is [here](/docs/doc/Rust%20Talk%202023.11.09.docx), in | ||
Microsoft Word format. I may adapt it for Markdown if I have some spare cycles. | ||
|
||
The other top-level directories correspond to the various functional and | ||
(intentionally) nonfunctional code samples used as props for the presentation. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "borrow" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
struct Wrapped<T>( | ||
T // Owner of some `T` | ||
); | ||
|
||
enum Either<'a, 'b, A, B> { | ||
A(&'a A), // Immutable borrow of some `A` with lifetime 'a | ||
B(&'b B), // Immutable borrow of some `B` with lifetime 'b | ||
} | ||
|
||
fn main() { | ||
let w = Wrapped(5); // Owner of `Wrapped(5)` | ||
let mut a = Either::A(&w); // Mutable Owner of `Either`; `w` immutably borrowed | ||
f(&mut a); // `a` mutably borrowed, updated by call | ||
} // `a` & `w` destroyed by end of block | ||
|
||
fn f<'a, A>( | ||
e: &mut Either<'a, 'a, A, A> // Mutable borrow of some `Either` | ||
) { | ||
*e = match e { | ||
Either::A(a) => // `a` owns borrow of `A` | ||
Either::B(a), // `e` becomes owner of new `Either`; `a` moved | ||
Either::B(b) => // `a` owns borrow of `A` | ||
Either::A(b) // `e` becomes owner of new `Either`; `b` moved | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "concurrent-arc-mutex" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use std::sync::{Arc, Mutex, MutexGuard}; | ||
use std::thread::{JoinHandle, spawn}; | ||
|
||
fn main() { | ||
let shared: Arc<Mutex<i32>> = Arc::new(Mutex::new(0)); | ||
let join_handles: Vec<JoinHandle<()>> = (1..=10) | ||
.map(|_| { // Don't care about the subscript, only running 10 times | ||
let copy = Arc::clone(&shared); | ||
spawn(move || { | ||
let mut guarded_value: MutexGuard<i32> = copy.lock().unwrap(); | ||
*guarded_value += 1; | ||
}) | ||
}) | ||
.collect(); // Iterators are lazy, so must collect | ||
// Wait for all threads to complete. | ||
join_handles.into_iter().for_each(|h| h.join().unwrap()); | ||
println!("{}", *shared.lock().unwrap()); // Prints "10\n" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "concurrent-arc" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use std::sync::Arc; | ||
use std::thread::spawn; | ||
|
||
fn main() { | ||
let shared: Arc<i32> = Arc::new(10); | ||
let copy = Arc::clone(&shared); | ||
let forked = spawn(move || { | ||
println!("first thread: {}", *copy); | ||
}); | ||
forked.join().unwrap(); | ||
println!("main thread: {}", *shared); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "concurrent-rc-in-arc" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::rc::Rc; | ||
use std::sync::Arc; | ||
use std::thread::spawn; | ||
|
||
fn main() { | ||
let shared: Arc<Rc<i32>> = | ||
Arc::new(Rc::new(10)); | ||
let copy = Arc::clone(&shared); | ||
let forked = spawn(move || | ||
{ | ||
println!("first thread: {}", **copy); | ||
} | ||
); | ||
forked.join().unwrap(); | ||
println!("main thread: {}", **shared); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "concurrent-rc" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use std::rc::Rc; | ||
use std::thread::spawn; | ||
|
||
fn main() { | ||
let shared: Rc<i32> = Rc::new(10); | ||
let copy = Rc::clone(&shared); | ||
let forked = spawn(move || | ||
{ | ||
println!("first thread: {}", *copy); | ||
} | ||
); | ||
forked.join().unwrap(); | ||
println!("main thread: {}", *shared); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.idea/ | ||
*.iml | ||
*.iws | ||
*.eml | ||
out/ | ||
.DS_Store | ||
.svn | ||
log/*.log | ||
tmp/** | ||
node_modules/ | ||
.sass-cache | ||
examples/ | ||
test/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/test | ||
/examples | ||
.github | ||
.sass-cache | ||
gulpfile.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (C) 2011-2023 Hakim El Hattab, http://hakim.se, and reveal.js contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<p align="center"> | ||
<a href="https://revealjs.com"> | ||
<img src="https://hakim-static.s3.amazonaws.com/reveal-js/logo/v1/reveal-black-text-sticker.png" alt="reveal.js" width="500"> | ||
</a> | ||
<br><br> | ||
<a href="https://github.com/hakimel/reveal.js/actions"><img src="https://github.com/hakimel/reveal.js/workflows/tests/badge.svg"></a> | ||
<a href="https://slides.com/"><img src="https://s3.amazonaws.com/static.slid.es/images/slides-github-banner-320x40.png?1" alt="Slides" width="160" height="20"></a> | ||
</p> | ||
|
||
reveal.js is an open source HTML presentation framework. It enables anyone with a web browser to create beautiful presentations for free. Check out the live demo at [revealjs.com](https://revealjs.com/). | ||
|
||
The framework comes with a powerful feature set including [nested slides](https://revealjs.com/vertical-slides/), [Markdown support](https://revealjs.com/markdown/), [Auto-Animate](https://revealjs.com/auto-animate/), [PDF export](https://revealjs.com/pdf-export/), [speaker notes](https://revealjs.com/speaker-view/), [LaTeX typesetting](https://revealjs.com/math/), [syntax highlighted code](https://revealjs.com/code/) and an [extensive API](https://revealjs.com/api/). | ||
|
||
--- | ||
|
||
Want to create reveal.js presentation in a graphical editor? Try <https://slides.com>. It's made by the same people behind reveal.js. | ||
|
||
--- | ||
|
||
### Sponsors | ||
Hakim's open source work is supported by <a href="https://github.com/sponsors/hakimel">GitHub sponsors</a>. Special thanks to: | ||
<div align="center"> | ||
<table> | ||
<td align="center"> | ||
<a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=revealjs&utm_source=github"> | ||
<div> | ||
<img src="https://user-images.githubusercontent.com/629429/151508669-efb4c3b3-8fe3-45eb-8e47-e9510b5f0af1.svg" width="290" alt="WorkOS"> | ||
</div> | ||
<b>Your app, enterprise-ready.</b> | ||
<div> | ||
<sub>Start selling to enterprise customers with just a few lines of code. Add Single Sign-On (and more) in minutes instead of months.</sup> | ||
</div> | ||
</a> | ||
</td> | ||
</table> | ||
</div> | ||
|
||
--- | ||
|
||
### Getting started | ||
- π [Install reveal.js](https://revealjs.com/installation) | ||
- π [View the demo presentation](https://revealjs.com/demo) | ||
- π [Read the documentation](https://revealjs.com/markup/) | ||
- π [Try the visual editor for reveal.js at Slides.com](https://slides.com/) | ||
- π¬ [Watch the reveal.js video course (paid)](https://revealjs.com/course) | ||
|
||
--- | ||
<div align="center"> | ||
MIT licensed | Copyright Β© 2011-2023 Hakim El Hattab, https://hakim.se | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
%%{init: {"flowchart": {"htmlLabels": false}} }%% | ||
flowchart LR | ||
Box --> Content | ||
subgraph stack | ||
direction BT | ||
Box | ||
end | ||
subgraph heap | ||
direction TB | ||
Content | ||
end |