From 1dbf74c0787aa9e63bf3240d51170e1d6bc7834a Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Fri, 14 Feb 2025 16:41:07 -0500 Subject: [PATCH 01/15] Add new image instead of ASCII art --- .../130_memory_management/01_review.rst | 16 +- .../review_of_program_memory.svg | 375 ++++++++++++++++++ 2 files changed, 376 insertions(+), 15 deletions(-) create mode 100644 images/comprehensive_rust_training/review_of_program_memory.svg diff --git a/courses/comprehensive_rust_training/130_memory_management/01_review.rst b/courses/comprehensive_rust_training/130_memory_management/01_review.rst index c38397a64..99e9265e2 100644 --- a/courses/comprehensive_rust_training/130_memory_management/01_review.rst +++ b/courses/comprehensive_rust_training/130_memory_management/01_review.rst @@ -34,21 +34,7 @@ dynamically sized data, the actual string, on the heap: let s1 = String::from("Hello"); } -.. code:: bob - - Stack - .- - - - - - - - - - - - - -. Heap - : : .- - - - - - - - - - - - - - - -. - : s1 : : : - : +-----------+-------+ : : : - : | capacity | 5 | : : +----+----+----+----+----+ : - : | ptr | o-+---+-----+-->| H | e | l | l | o | : - : | len | 5 | : : +----+----+----+----+----+ : - : +-----------+-------+ : : : - : : : : - `- - - - - - - - - - - - - -' `- - - - - - - - - - - - - - - -' - -.. raw:: html +.. image:: comprehensive_rust_training/review_of_program_memory.svg --------- Details diff --git a/images/comprehensive_rust_training/review_of_program_memory.svg b/images/comprehensive_rust_training/review_of_program_memory.svg new file mode 100644 index 000000000..3dc5c7c33 --- /dev/null +++ b/images/comprehensive_rust_training/review_of_program_memory.svg @@ -0,0 +1,375 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + capacity +ptr +len + 5 + +5 + + + s1 + Stack + + + H + + l + + l + + o + + + e + + + Heap + + + + From 319a78eba7e5c3e691da240839b5f0c0de0c0514 Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Mon, 17 Feb 2025 15:29:43 -0500 Subject: [PATCH 02/15] Fix alignment of text --- .../review_of_program_memory.svg | 382 +++++++++--------- 1 file changed, 187 insertions(+), 195 deletions(-) diff --git a/images/comprehensive_rust_training/review_of_program_memory.svg b/images/comprehensive_rust_training/review_of_program_memory.svg index 3dc5c7c33..b54438691 100644 --- a/images/comprehensive_rust_training/review_of_program_memory.svg +++ b/images/comprehensive_rust_training/review_of_program_memory.svg @@ -23,9 +23,9 @@ inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" - inkscape:zoom="2.0792508" - inkscape:cx="235.42133" - inkscape:cy="75.748436" + inkscape:zoom="8.3170032" + inkscape:cx="381.56773" + inkscape:cy="124.74445" inkscape:window-width="2560" inkscape:window-height="1369" inkscape:window-x="-8" @@ -175,201 +175,193 @@ inkscape:groupmode="layer" id="layer1" transform="translate(-26.317115,-45.150018)"> - - capacity + capacity ptr + x="57.712891" + y="148.25514" + id="tspan13">ptr len - 5 + x="57.712891" + y="174.92176" + id="tspan14">len + 5 + x="57.712891" + y="148.25514" + id="tspan16"> 5 - - - s1 - Stack - - - H - - l - - l - - o - - - e - - - Heap - - + x="57.712891" + y="174.92176" + id="tspan17">5 + + + s1 + Stack + + + H + + l + + l + + o + + e + + Heap + From ade59b881d80de9898532baa2db492dc1ef419a1 Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Mon, 17 Feb 2025 15:30:01 -0500 Subject: [PATCH 03/15] Add image illustrating move of a pointer --- .../130_memory_management/04_move.rst | 38 +- .../move_semantics_2.svg | 483 ++++++++++++++++++ 2 files changed, 486 insertions(+), 35 deletions(-) create mode 100644 images/comprehensive_rust_training/move_semantics_2.svg diff --git a/courses/comprehensive_rust_training/130_memory_management/04_move.rst b/courses/comprehensive_rust_training/130_memory_management/04_move.rst index 04f9a8707..6bf90e849 100644 --- a/courses/comprehensive_rust_training/130_memory_management/04_move.rst +++ b/courses/comprehensive_rust_training/130_memory_management/04_move.rst @@ -11,7 +11,7 @@ An assignment will transfer *ownership* between variables: .. code:: rust,editable fn main() { - let s1: String = String::from("Hello!"); + let s1: String = String::from("Hello"); let s2: String = s1; println!("s2: {s2}"); // println!("s1: {s1}"); @@ -24,43 +24,11 @@ An assignment will transfer *ownership* between variables: Before move to ``s2``: -.. code:: bob - - Stack Heap - .- - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - - - - -. - : : : : - : s1 : : : - : +-----------+-------+ : : +----+----+----+----+----+----+ : - : | ptr | o---+---+-----+-->| H | e | l | l | o | ! | : - : | len | 6 | : : +----+----+----+----+----+----+ : - : | capacity | 6 | : : : - : +-----------+-------+ : : : - : : `- - - - - - - - - - - - - - - - - - -' - : : - `- - - - - - - - - - - - - -' +.. image:: comprehensive_rust_training/review_of_program_memory.svg After move to ``s2``: -.. code:: bob - - Stack Heap - .- - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - - - - -. - : : : : - : s1 "(inaccessible)" : : : - : +-----------+-------+ : : +----+----+----+----+----+----+ : - : | ptr | o---+---+--+--+-->| H | e | l | l | o | ! | : - : | len | 6 | : | : +----+----+----+----+----+----+ : - : | capacity | 6 | : | : : - : +-----------+-------+ : | : : - : : | `- - - - - - - - - - - - - - - - - - -' - : s2 : | - : +-----------+-------+ : | - : | ptr | o---+---+--' - : | len | 6 | : - : | capacity | 6 | : - : +-----------+-------+ : - : : - `- - - - - - - - - - - - - -' +.. image:: comprehensive_rust_training/move_semantics_2.svg When you pass a value to a function, the value is assigned to the function parameter. This transfers ownership: diff --git a/images/comprehensive_rust_training/move_semantics_2.svg b/images/comprehensive_rust_training/move_semantics_2.svg new file mode 100644 index 000000000..20b82fb8d --- /dev/null +++ b/images/comprehensive_rust_training/move_semantics_2.svg @@ -0,0 +1,483 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Stack + + + H + + l + + l + + o + + e + + Heap + + capacity +ptr +len + 5 + +5 + + + s1 (inaccessible) + + + capacity +ptr +len + 5 + +5 + + + s2 + + + + From 0220eb814def7c1d60375ba36bd38ff74fff50f1 Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Mon, 17 Feb 2025 15:38:47 -0500 Subject: [PATCH 04/15] Add copy-assignment images also remove empty slide --- .../130_memory_management/04_move.rst | 41 ++----------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/courses/comprehensive_rust_training/130_memory_management/04_move.rst b/courses/comprehensive_rust_training/130_memory_management/04_move.rst index 6bf90e849..8bbca5912 100644 --- a/courses/comprehensive_rust_training/130_memory_management/04_move.rst +++ b/courses/comprehensive_rust_training/130_memory_management/04_move.rst @@ -83,10 +83,6 @@ In the ``say_hello`` example: More to Explore ================= ------------------ -More to Explore ------------------ - -------------------------------- Defensive Copies in Modern C++ -------------------------------- @@ -95,7 +91,7 @@ Modern C++ solves this differently: .. code:: cpp - std::string s1 = "Cpp"; + std::string s1 = "Hello"; std::string s2 = s1; // Duplicate the data in s1. - The heap data from ``s1`` is duplicated and ``s2`` gets its own @@ -105,42 +101,11 @@ Modern C++ solves this differently: Before copy-assignment: -.. code:: bob - - Stack Heap - .- - - - - - - - - - - - - -. .- - - - - - - - - - - -. - : : : : - : s1 : : : - : +-----------+-------+ : : +----+----+----+ : - : | ptr | o---+---+--+--+-->| C | p | p | : - : | len | 3 | : : +----+----+----+ : - : | capacity | 3 | : : : - : +-----------+-------+ : : : - : : `- - - - - - - - - - - -' - `- - - - - - - - - - - - - -' +.. image:: comprehensive_rust_training/review_of_program_memory.svg After copy-assignment: -.. code:: bob - - Stack Heap - .- - - - - - - - - - - - - -. .- - - - - - - - - - - -. - : : : : - : s1 : : : - : +-----------+-------+ : : +----+----+----+ : - : | ptr | o---+---+--+--+-->| C | p | p | : - : | len | 3 | : : +----+----+----+ : - : | capacity | 3 | : : : - : +-----------+-------+ : : : - : : : : - : s2 : : : - : +-----------+-------+ : : +----+----+----+ : - : | ptr | o---+---+-----+-->| C | p | p | : - : | len | 3 | : : +----+----+----+ : - : | capacity | 3 | : : : - : +-----------+-------+ : : : - : : `- - - - - - - - - - - -' - `- - - - - - - - - - - - - -' +.. image:: comprehensive_rust_training/copy_assignment_2.svg Key points: From 755fccf02b1dc0e8430a44181b31b8d2caba0ee5 Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Mon, 17 Feb 2025 15:39:16 -0500 Subject: [PATCH 05/15] Add image showing stack/heap after pointer copy --- .../copy_assignment_2.svg | 598 ++++++++++++++++++ 1 file changed, 598 insertions(+) create mode 100644 images/comprehensive_rust_training/copy_assignment_2.svg diff --git a/images/comprehensive_rust_training/copy_assignment_2.svg b/images/comprehensive_rust_training/copy_assignment_2.svg new file mode 100644 index 000000000..518302cb3 --- /dev/null +++ b/images/comprehensive_rust_training/copy_assignment_2.svg @@ -0,0 +1,598 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Stack + + + Heap + capacity +ptr +len + 5 + +5 + + + s1 + H + + l + + l + + o + + e + + + capacity +ptr +len + 5 + +5 + + + s2 + H + + l + + l + + o + + e + + + + From 1373549468114338db266168b8d9adcca47432a1 Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Tue, 18 Feb 2025 09:25:27 -0500 Subject: [PATCH 06/15] Fix font sizing issue --- .../copy_assignment_2.svg | 20 +- .../move_semantics_2.svg | 295 +++++++++--------- .../review_of_program_memory.svg | 162 ++++++---- 3 files changed, 267 insertions(+), 210 deletions(-) diff --git a/images/comprehensive_rust_training/copy_assignment_2.svg b/images/comprehensive_rust_training/copy_assignment_2.svg index 518302cb3..39df675fd 100644 --- a/images/comprehensive_rust_training/copy_assignment_2.svg +++ b/images/comprehensive_rust_training/copy_assignment_2.svg @@ -270,9 +270,9 @@ len @@ -342,7 +342,7 @@ id="rect3-5-6" width="7.7998013" height="19.868061" - x="62.086197" + x="69.212158" y="68.493034" /> len @@ -492,7 +492,7 @@ id="rect3-5-6-4" width="7.7998013" height="19.868061" - x="62.086197" + x="69.212158" y="101.22944" /> diff --git a/images/comprehensive_rust_training/move_semantics_2.svg b/images/comprehensive_rust_training/move_semantics_2.svg index 20b82fb8d..67509446d 100644 --- a/images/comprehensive_rust_training/move_semantics_2.svg +++ b/images/comprehensive_rust_training/move_semantics_2.svg @@ -2,9 +2,9 @@ + id="rect2-4-9-8" /> + id="rect2-6-0-8" /> + id="rect2-6-5-0-2" /> + + + + id="path17-9-7" /> + transform="translate(-27.820606,-48.434999)"> Stack + y="56.710953">Stack + width="54.271706" + height="72.532486" + x="36.05204" + y="59.208584" + ry="9.8436947" /> + Heap + capacity +ptr +len + 5 + +5 + style="fill:none;stroke:#000000;stroke-width:1.065" + id="rect3-6" + width="28.249357" + height="19.850899" + x="41.014862" + y="68.497894" /> + + s1 (inaccessible) H + id="tspan7">H l + id="tspan8">l l + id="tspan9">l o + id="tspan10">o e + id="tspan11">e + Heap - - capacity -ptr -len - 5 - -5 - - - s1 (inaccessible) - - - capacity + id="tspan12">capacity ptr + id="tspan13">ptr len + id="tspan14">len 5 + id="tspan15">5 + id="tspan16"> 5 - + id="tspan17">5 + y="101.2343" /> + s2 + y="99.325554">s2 + style="fill:none;stroke:#000000;stroke-width:1.065;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4.3;stroke-dasharray:none;stroke-dashoffset:0;marker-start:url(#Dot-8-1)" + d="M 73.381149,111.14637 H 99.501105" + id="path8-6-9" /> + d="M 98.96861,78.457702 V 110.83118" + id="path8-6-9-3" /> + diff --git a/images/comprehensive_rust_training/review_of_program_memory.svg b/images/comprehensive_rust_training/review_of_program_memory.svg index b54438691..a9c1234c7 100644 --- a/images/comprehensive_rust_training/review_of_program_memory.svg +++ b/images/comprehensive_rust_training/review_of_program_memory.svg @@ -2,9 +2,9 @@ + + + + + + + + transform="translate(-28.155349,-48.133497)"> + Stack + + + Heap capacity + id="tspan1">capacity ptr + id="tspan2">ptr len + id="tspan3">len 5 + id="tspan4">5 + id="tspan5"> 5 + id="tspan6">5 @@ -223,7 +303,7 @@ id="rect3-5-6" width="7.7998013" height="19.868061" - x="62.086197" + x="69.212158" y="68.493034" /> s1 - Stack - - H + id="tspan7">H l + id="tspan8">l l + id="tspan9">l o + id="tspan10">o e + id="tspan11">e - Heap From e3512d0ee4c9aa30a3e038976939edee93547bef Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:39:57 -0500 Subject: [PATCH 07/15] Fix font --- .../copy_assignment_2.svg | 533 ++++++++---------- .../move_semantics_2.svg | 382 ++++++------- .../review_of_program_memory.svg | 266 ++++----- 3 files changed, 560 insertions(+), 621 deletions(-) diff --git a/images/comprehensive_rust_training/copy_assignment_2.svg b/images/comprehensive_rust_training/copy_assignment_2.svg index 39df675fd..7cec675d9 100644 --- a/images/comprehensive_rust_training/copy_assignment_2.svg +++ b/images/comprehensive_rust_training/copy_assignment_2.svg @@ -3,8 +3,8 @@ + + + + id="path17-9-8" /> + id="path135-4-2" /> + + transform="translate(-28.155349,-48.133497)"> Stack + x="35.345909" + y="57.410824">Stack - + y="59.208805" + ry="9.943327" /> Heap - capacity + x="107.62312" + y="67.787117">Heap + + capacity ptr + x="57.712891" + y="148.25514" + id="tspan16">ptr len - 5 + x="57.712891" + y="174.92176" + id="tspan17">len + 5 + x="57.712891" + y="148.25514" + id="tspan19"> 5 + x="57.712891" + y="174.92176" + id="tspan20">5 + + y="68.498543" /> + y="68.492813" /> s1 - H - - l - - l - - o - - e - - - capacity + + capacity ptr + x="57.712891" + y="148.25514" + id="tspan22">ptr len - 5 + x="57.712891" + y="174.92176" + id="tspan23">len + 5 + x="57.712891" + y="148.25514" + id="tspan25"> 5 + x="57.712891" + y="174.92176" + id="tspan26">5 + + y="103.05671" /> + y="103.05098" /> s2 - H - - l - - l + y="101.14732">s2 - o - - e - - + style="fill:none;stroke:#000000;stroke-width:1.065;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4.3;stroke-dasharray:2.12998, 1.065;stroke-dashoffset:0" + id="rect6-2-7" + width="44.156372" + height="54.021297" + x="108.54868" + y="69.479691" + ry="7.3314624" /> + + + + H e l l o + + + + + + + + + + + + + + + + H e l l o + + + + + + + + + + + + diff --git a/images/comprehensive_rust_training/move_semantics_2.svg b/images/comprehensive_rust_training/move_semantics_2.svg index 67509446d..9f434d739 100644 --- a/images/comprehensive_rust_training/move_semantics_2.svg +++ b/images/comprehensive_rust_training/move_semantics_2.svg @@ -3,8 +3,8 @@ + + + + id="path17-9-0" /> + transform="translate(-28.155349,-48.133497)"> Stack + x="35.345909" + y="57.410824">Stack + y="59.208805" + ry="9.943327" /> Heap - capacity + x="107.62312" + y="67.787117">Heap + + capacity ptr + x="57.712891" + y="148.25514" + id="tspan8">ptr len - 5 + x="57.712891" + y="174.92176" + id="tspan9">len + 5 + x="57.712891" + y="148.25514" + id="tspan11"> 5 + x="57.712891" + y="174.92176" + id="tspan12">5 + + y="68.498543" /> + y="68.492813" /> s1 (inaccessible) - H - - l - - l - - o - - e - - capacity + + capacity ptr + x="57.712891" + y="148.25514" + id="tspan14">ptr len - 5 + x="57.712891" + y="174.92176" + id="tspan15">len + 5 + x="57.712891" + y="148.25514" + id="tspan17"> 5 + x="57.712891" + y="174.92176" + id="tspan18">5 + + y="103.05671" /> + y="103.05098" /> s2 + y="101.14732">s2 + style="fill:none;stroke:#000000;stroke-width:1.065;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4.3;stroke-dasharray:none;stroke-dashoffset:0;marker-start:url(#Dot-8-9)" + d="M 73.105952,114.76233 H 98.339524" + id="path8-6-6" /> - + d="M 97.808486,80.193047 V 114.92938" + id="path8-6-6-6" /> + + + + H e l l o + + + + + + + + + + + + diff --git a/images/comprehensive_rust_training/review_of_program_memory.svg b/images/comprehensive_rust_training/review_of_program_memory.svg index a9c1234c7..55f5bd4ec 100644 --- a/images/comprehensive_rust_training/review_of_program_memory.svg +++ b/images/comprehensive_rust_training/review_of_program_memory.svg @@ -23,9 +23,9 @@ inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" - inkscape:zoom="2.0792508" - inkscape:cx="258.02563" - inkscape:cy="273.41579" + inkscape:zoom="4.1585016" + inkscape:cx="242.27477" + inkscape:cy="131.41753" inkscape:window-width="2560" inkscape:window-height="1369" inkscape:window-x="-8" @@ -34,6 +34,12 @@ inkscape:current-layer="layer1" /> + Stack + x="35.345909" + y="57.410824">Stack - + y="59.208805" + ry="5.1808729" /> Heap - capacity + x="107.62312" + y="67.787117">Heap + + capacity ptr + x="57.712891" + y="148.25514" + id="tspan2">ptr len - 5 + x="57.712891" + y="174.92176" + id="tspan4">len + 5 + x="57.712891" + y="148.25514" + id="tspan6"> 5 + x="57.712891" + y="174.92176" + id="tspan7">5 + + y="68.498543" /> + y="68.492813" /> s1 - H - - l - - l - - o - - e - + + + + H e l l o + + + + + + + + + + + + From f4963e4bd131ed3573af6aabe5b8926a4b63a8bf Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:22:11 -0500 Subject: [PATCH 08/15] Sizing issue --- .../copy_assignment_2.svg | 203 +++++++++--------- .../move_semantics_2.svg | 142 ++++++------ .../review_of_program_memory.svg | 126 ++++++----- 3 files changed, 224 insertions(+), 247 deletions(-) diff --git a/images/comprehensive_rust_training/copy_assignment_2.svg b/images/comprehensive_rust_training/copy_assignment_2.svg index 7cec675d9..1e580a7dc 100644 --- a/images/comprehensive_rust_training/copy_assignment_2.svg +++ b/images/comprehensive_rust_training/copy_assignment_2.svg @@ -448,118 +448,107 @@ x="108.54868" y="69.479691" ry="7.3314624" /> + + H e l l o + id="g3" + transform="matrix(1,0,0,1.3319299,4.04099,-48.677881)" + style="stroke-width:0.866482"> + + + + + + + - - H e l l o - - - - - - - - - - - + style="fill:none;stroke:#000000;stroke-width:0.433241;stroke-linejoin:round;stroke-miterlimit:4.3" + d="m 143.06336,94.059332 v 5.408102" + id="path3-2-8" /> + id="g3-57" + transform="matrix(1,0,0,1.3319299,4.04099,-13.987473)" + style="stroke-width:0.866482"> - - H e l l o - - - - - - - - - - - + style="fill:none;stroke:#000000;stroke-width:0.433241;stroke-linejoin:round;stroke-miterlimit:4.3" + d="m 110.10394,94.059332 v 5.408096" + id="path3-6" /> + + + + + + + + + H e l l o diff --git a/images/comprehensive_rust_training/move_semantics_2.svg b/images/comprehensive_rust_training/move_semantics_2.svg index 9f434d739..49c8725d7 100644 --- a/images/comprehensive_rust_training/move_semantics_2.svg +++ b/images/comprehensive_rust_training/move_semantics_2.svg @@ -23,9 +23,9 @@ inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" - inkscape:zoom="1.4702523" - inkscape:cx="-206.42715" - inkscape:cy="135.01084" + inkscape:zoom="2.9405046" + inkscape:cx="454.17375" + inkscape:cy="222.92092" inkscape:window-width="2560" inkscape:window-height="1369" inkscape:window-x="-8" @@ -297,15 +297,15 @@ y="0">capacity + id="tspan1">capacity ptr + id="tspan2">ptr len + id="tspan3">len 5 + id="tspan4">5 + id="tspan5"> 5 + id="tspan6">5 capacity + id="tspan7">capacity ptr + id="tspan8">ptr len + id="tspan9">len 5 + id="tspan10">5 + id="tspan11"> 5 + id="tspan12">5 + + H e l l o - - - H e l l o - - - - - - - - - - - + id="g3-3" + transform="matrix(1,0,0,1.3319299,4.0743695,-48.677881)" + style="stroke-width:0.866482"> + + + + + + + + diff --git a/images/comprehensive_rust_training/review_of_program_memory.svg b/images/comprehensive_rust_training/review_of_program_memory.svg index 55f5bd4ec..5e4569839 100644 --- a/images/comprehensive_rust_training/review_of_program_memory.svg +++ b/images/comprehensive_rust_training/review_of_program_memory.svg @@ -24,7 +24,7 @@ inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" inkscape:zoom="4.1585016" - inkscape:cx="242.27477" + inkscape:cx="242.51524" inkscape:cy="131.41753" inkscape:window-width="2560" inkscape:window-height="1369" @@ -265,15 +265,15 @@ y="0">capacity + id="tspan3">capacity ptr + id="tspan10">ptr len + id="tspan11">len 5 + id="tspan12">5 + id="tspan13"> 5 + id="tspan14">5 + + H e l l o - - - H e l l o - - - - - - - - - - - + id="g3-3" + transform="matrix(1,0,0,1.3319299,4.0397118,-48.677881)" + style="stroke-width:0.866482"> + + + + + + + + From 033cb59292de8e827d0e09b4eaf0c2925085bd75 Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Tue, 18 Feb 2025 15:13:33 -0500 Subject: [PATCH 09/15] Add images for Pattern Matching exercise --- .../080_pattern_matching/05_exercise.rst | 29 +- .../pattern_matching_exercise_1.svg | 162 +++++++ .../pattern_matching_exercise_2.svg | 458 ++++++++++++++++++ 3 files changed, 623 insertions(+), 26 deletions(-) create mode 100644 images/comprehensive_rust_training/pattern_matching_exercise_1.svg create mode 100644 images/comprehensive_rust_training/pattern_matching_exercise_2.svg diff --git a/courses/comprehensive_rust_training/080_pattern_matching/05_exercise.rst b/courses/comprehensive_rust_training/080_pattern_matching/05_exercise.rst index c27dc8729..6f5a97e74 100644 --- a/courses/comprehensive_rust_training/080_pattern_matching/05_exercise.rst +++ b/courses/comprehensive_rust_training/080_pattern_matching/05_exercise.rst @@ -15,15 +15,8 @@ evaluates to ``30``. We can represent the expression as a tree: -.. code:: bob - - .-------. - .------ | + | ------. - | '-------' | - v v - .--------. .--------. - | 10 | | 20 | - '--------' '--------' +.. image:: comprehensive_rust_training/pattern_matching_exercise_1.svg + :width: 40% A bigger and more complex expression would be ``(10 * 9) + ((3 - 4) * 5)``, which evaluate to ``85``. We represent @@ -33,23 +26,7 @@ this as a much bigger tree: -.. code:: bob - - .-----. - .---------------- | + | ----------------. - | '-----' | - v v - .-----. .-----. - .---- | * | ----. .---- | * | ----. - | '-----' | | '-----' | - v v v v - .------. .-----. .-----. .-----. - | 10 | | 9 | .---- | "-"| ----. | 5 | - '------' '-----' | '-----' | '-----' - v v - .-----. .-----. - | 3 | | 4 | - '-----' '-----' +.. image:: comprehensive_rust_training/pattern_matching_exercise_2.svg In code, we will represent the tree with two types: diff --git a/images/comprehensive_rust_training/pattern_matching_exercise_1.svg b/images/comprehensive_rust_training/pattern_matching_exercise_1.svg new file mode 100644 index 000000000..0e6d47767 --- /dev/null +++ b/images/comprehensive_rust_training/pattern_matching_exercise_1.svg @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + 20 + + 10 + + + + + + + + + + + + diff --git a/images/comprehensive_rust_training/pattern_matching_exercise_2.svg b/images/comprehensive_rust_training/pattern_matching_exercise_2.svg new file mode 100644 index 000000000..c07befeae --- /dev/null +++ b/images/comprehensive_rust_training/pattern_matching_exercise_2.svg @@ -0,0 +1,458 @@ + + + + + + + + + * + + 9 + + 10 + + + + + + + + + + + - + + 4 + + 3 + + + + * + + 5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From d484f541b5687f335278b7e92d26cf6b6381f9da Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Tue, 18 Feb 2025 15:31:11 -0500 Subject: [PATCH 10/15] Fix stroke attribute on text --- .../pattern_matching_exercise_1.svg | 148 +++--- .../pattern_matching_exercise_2.svg | 456 ++++++++---------- 2 files changed, 274 insertions(+), 330 deletions(-) diff --git a/images/comprehensive_rust_training/pattern_matching_exercise_1.svg b/images/comprehensive_rust_training/pattern_matching_exercise_1.svg index 0e6d47767..a5bf7edf0 100644 --- a/images/comprehensive_rust_training/pattern_matching_exercise_1.svg +++ b/images/comprehensive_rust_training/pattern_matching_exercise_1.svg @@ -23,9 +23,9 @@ inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" - inkscape:zoom="5.8810094" - inkscape:cx="210.08298" - inkscape:cy="75.752302" + inkscape:zoom="2.9405047" + inkscape:cx="203.53649" + inkscape:cy="78.727982" inkscape:window-width="2560" inkscape:window-height="1369" inkscape:window-x="-8" @@ -39,29 +39,25 @@ inkscape:groupmode="layer" id="layer1" transform="translate(-20.673317,-4.070765)"> - - - + - + + + 20 10 - - - - - - - - + + + + diff --git a/images/comprehensive_rust_training/pattern_matching_exercise_2.svg b/images/comprehensive_rust_training/pattern_matching_exercise_2.svg index c07befeae..536c6051a 100644 --- a/images/comprehensive_rust_training/pattern_matching_exercise_2.svg +++ b/images/comprehensive_rust_training/pattern_matching_exercise_2.svg @@ -23,9 +23,9 @@ inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" - inkscape:zoom="1.4702523" - inkscape:cx="220.71041" - inkscape:cy="61.554059" + inkscape:zoom="2.9405047" + inkscape:cx="435.46947" + inkscape:cy="140.62212" inkscape:window-width="2560" inkscape:window-height="1369" inkscape:window-x="-8" @@ -49,13 +49,13 @@ ry="2.7447925" /> * 9 10 - - - + - + + + - 4 3 * 5 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + From 5eb1fb7d84f4cf667da765ad98433cdd8abc87cc Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Tue, 18 Feb 2025 16:05:12 -0500 Subject: [PATCH 11/15] Add images for Smart Pointers - Box chapter --- .../140_smart_pointers/01_box.rst | 29 +- .../smart_pointers_box_1.svg | 302 +++++++++++ .../smart_pointers_box_2.svg | 489 ++++++++++++++++++ 3 files changed, 794 insertions(+), 26 deletions(-) create mode 100644 images/comprehensive_rust_training/smart_pointers_box_1.svg create mode 100644 images/comprehensive_rust_training/smart_pointers_box_2.svg diff --git a/courses/comprehensive_rust_training/140_smart_pointers/01_box.rst b/courses/comprehensive_rust_training/140_smart_pointers/01_box.rst index 3f7842256..7fe2fb315 100644 --- a/courses/comprehensive_rust_training/140_smart_pointers/01_box.rst +++ b/courses/comprehensive_rust_training/140_smart_pointers/01_box.rst @@ -16,18 +16,8 @@ owned pointer to data on the heap: println!("five: {}", *five); } -.. code:: bob - - Stack Heap - .- - - - - - -. .- - - - - - -. - : : : : - : five : : : - : +-----+ : : +-----+ : - : | o---|---+-----+-->| 5 | : - : +-----+ : : +-----+ : - : : : : - : : : : - `- - - - - - -' `- - - - - - -' +.. image:: comprehensive_rust_training/smart_pointers_box_1.svg + :width: 50% ``Box`` implements ``Deref``, which means that you can :url:`call methods from T directly on a Box `. @@ -52,20 +42,7 @@ indirection: println!("{list:?}"); } -.. code:: bob - - Stack Heap - .- - - - - - - - - - - - - - . .- - - - - - - - - - - - - - - - - - - - - - - - -. - : : : : - : list : : : - : +---------+----+----+ : : +---------+----+----+ +------+----+----+ : - : | Element | 1 | o--+----+-----+--->| Element | 2 | o--+--->| Nil | // | // | : - : +---------+----+----+ : : +---------+----+----+ +------+----+----+ : - : : : : - : : : : - '- - - - - - - - - - - - - - ' '- - - - - - - - - - - - - - - - - - - - - - - - -' - -.. raw:: html +.. image:: comprehensive_rust_training/smart_pointers_box_2.svg --------- Details diff --git a/images/comprehensive_rust_training/smart_pointers_box_1.svg b/images/comprehensive_rust_training/smart_pointers_box_1.svg new file mode 100644 index 000000000..23eec795c --- /dev/null +++ b/images/comprehensive_rust_training/smart_pointers_box_1.svg @@ -0,0 +1,302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Stack + + Heap + + five + + + 5 + + + diff --git a/images/comprehensive_rust_training/smart_pointers_box_2.svg b/images/comprehensive_rust_training/smart_pointers_box_2.svg new file mode 100644 index 000000000..785df6428 --- /dev/null +++ b/images/comprehensive_rust_training/smart_pointers_box_2.svg @@ -0,0 +1,489 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Stack + + Heap + list + + + Element + 1 + + + + + Element + 2 + + + + Nil + // + + + + // + + + From 05d18c9f959db0ceba828798c16478d847944764 Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Tue, 18 Feb 2025 16:47:55 -0500 Subject: [PATCH 12/15] Add image for smart pointers owned trait objects --- .../140_smart_pointers/03_trait_objects.rst | 34 +- .../smart_pointers_owned_objects.svg | 791 ++++++++++++++++++ 2 files changed, 792 insertions(+), 33 deletions(-) create mode 100644 images/comprehensive_rust_training/smart_pointers_owned_objects.svg diff --git a/courses/comprehensive_rust_training/140_smart_pointers/03_trait_objects.rst b/courses/comprehensive_rust_training/140_smart_pointers/03_trait_objects.rst index 7eb764bbe..c2ca7fa61 100644 --- a/courses/comprehensive_rust_training/140_smart_pointers/03_trait_objects.rst +++ b/courses/comprehensive_rust_training/140_smart_pointers/03_trait_objects.rst @@ -48,39 +48,7 @@ like ``Box`` to create an owned trait object: ``Box``. Memory layout after allocating ``pets``: -.. code:: bob - - Stack Heap - .- - - - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - - - - - - - - -. - : : : : - : "pets: Vec>" : : "data: Cat" +----+----+----+----+ : - : +-----------+-------+ : : +-------+-------+ | F | i | d | o | : - : | ptr | o---+-------+--. : | lives | 9 | +----+----+----+----+ : - : | len | 2 | : | : +-------+-------+ ^ : - : | capacity | 2 | : | : ^ | : - : +-----------+-------+ : | : | '-------. : - : : | : | data:"Dog"| : - : : | : | +-------+--|-------+ : - `- - - - - - - - - - - - - - - -' | : +---|-+-----+ | name | o, 4, 4 | : - `--+-->| o o | o o-|----->| age | 5 | : - : +-|---+-|---+ +-------+----------+ : - : | | : - `- - -| - - |- - - - - - - - - - - - - - - - -' - | | - | | "Program text" - .- - -| - - |- - - - - - - - - - - - - - - - -. - : | | vtable : - : | | +----------------------+ : - : | `----->| "::talk" | : - : | +----------------------+ : - : | vtable : - : | +----------------------+ : - : '----------->| "::talk" | : - : +----------------------+ : - : : - '- - - - - - - - - - - - - - - - - - - - - - -' - -.. raw:: html +.. image:: comprehensive_rust_training/smart_pointers_owned_objects.svg --------- Details diff --git a/images/comprehensive_rust_training/smart_pointers_owned_objects.svg b/images/comprehensive_rust_training/smart_pointers_owned_objects.svg new file mode 100644 index 000000000..fa3feabd3 --- /dev/null +++ b/images/comprehensive_rust_training/smart_pointers_owned_objects.svg @@ -0,0 +1,791 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Stack + + Heap + + capacity +ptr +len + 2 + +2 + + + + pets: Vec<Box<dyn Pet>> + + Program text + + + F i d o + + + + + + + + + + + + + lives + + + + + 9 + data: Cat + + + name +age + ., 4, 4 +5 + data: Dog + + + + <Dog as Pet>::talk + vtable + + <Cat as Pet>::talk + vtable + + + + + + + + From 1386df0d79d88945e042c5dc8246258d0f0ca61f Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Tue, 18 Feb 2025 17:13:25 -0500 Subject: [PATCH 13/15] Fix sizing issues --- .../smart_pointers_owned_objects.svg | 704 +++++++++--------- 1 file changed, 347 insertions(+), 357 deletions(-) diff --git a/images/comprehensive_rust_training/smart_pointers_owned_objects.svg b/images/comprehensive_rust_training/smart_pointers_owned_objects.svg index fa3feabd3..6a59e4867 100644 --- a/images/comprehensive_rust_training/smart_pointers_owned_objects.svg +++ b/images/comprehensive_rust_training/smart_pointers_owned_objects.svg @@ -23,9 +23,9 @@ inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" - inkscape:zoom="1.4702523" - inkscape:cx="295.52751" - inkscape:cy="366.26367" + inkscape:zoom="1.0396254" + inkscape:cx="565.10741" + inkscape:cy="504.50866" inkscape:window-width="2560" inkscape:window-height="1369" inkscape:window-x="-8" @@ -407,385 +407,375 @@ style="stroke-width:0.5" x="124.16282" y="80.435921" /> + Stack + + Heap + id="g5" + transform="translate(-5.7588111,8.1956414)"> Stack - - Heap - - capacity -ptr -len - 2 - -2 - - - - pets: Vec<Box<dyn Pet>> - - Program text - - - F i d o - - - - - - - - - - - - - lives - - - - - 9 - capacity +data: Cat - - + y="148.25514" + id="tspan8">ptr +len name + id="tspan10">2 age - ., 4, 4 -5 - +data: Dog + y="174.92176" + id="tspan12">2 + + + + pets: Vec<Box<dyn Pet>> + + Program text + + F i d o + + style="fill:none;stroke:#000000;stroke-width:0.463396;stroke-linejoin:miter;stroke-miterlimit:4.3" + d="m 146.90632,84.835728 v 6.568459" + id="path4" /> - - <Dog as Pet>::talk - vtable - - <Cat as Pet>::talk - vtable + style="fill:none;stroke:#000000;stroke-width:0.463396;stroke-linejoin:miter;stroke-miterlimit:4.3" + d="m 172.30156,84.835728 v 6.568459" + id="path4-6" /> + style="fill:none;stroke:#000000;stroke-width:0.463396;stroke-linejoin:miter;stroke-miterlimit:4.3" + d="m 165.95275,84.835728 v 6.568459" + id="path4-0" /> + style="fill:none;stroke:#000000;stroke-width:0.463396;stroke-linejoin:miter;stroke-miterlimit:4.3" + d="m 159.60394,84.835728 v 6.568459" + id="path4-8" /> + style="fill:none;stroke:#000000;stroke-width:0.463396;stroke-linejoin:miter;stroke-miterlimit:4.3" + d="m 153.25513,84.835728 v 6.568459" + id="path4-4" /> + style="fill:none;stroke:#000000;stroke-width:0.463396;stroke-linejoin:miter;stroke-miterlimit:4.3" + d="m 146.65632,85.067623 h 25.89524" + id="path5" /> + style="fill:none;stroke:#000000;stroke-width:0.463396;stroke-linejoin:miter;stroke-miterlimit:4.3" + d="m 146.64991,91.154188 h 25.89524" + id="path5-8" /> + + lives + + + + 9 + data: Cat + + + name +age + ., 4, 4 +5 + data: Dog + + + + <Dog as Pet>::talk + vtable + + <Cat as Pet>::talk + vtable + + + + + From ece72c6a5e3e7d44f7cb9e49e97df14396ced4d3 Mon Sep 17 00:00:00 2001 From: Michael Frank <55284511+frank-at-adacore@users.noreply.github.com> Date: Wed, 19 Feb 2025 10:18:22 -0500 Subject: [PATCH 14/15] More tweaks for CI build version --- .../smart_pointers_owned_objects.svg | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/images/comprehensive_rust_training/smart_pointers_owned_objects.svg b/images/comprehensive_rust_training/smart_pointers_owned_objects.svg index 6a59e4867..8323cfeac 100644 --- a/images/comprehensive_rust_training/smart_pointers_owned_objects.svg +++ b/images/comprehensive_rust_training/smart_pointers_owned_objects.svg @@ -23,9 +23,9 @@ inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" - inkscape:zoom="1.0396254" - inkscape:cx="565.10741" - inkscape:cy="504.50866" + inkscape:zoom="2.9405046" + inkscape:cx="602.44762" + inkscape:cy="328.34501" inkscape:window-width="2560" inkscape:window-height="1369" inkscape:window-x="-8" @@ -421,9 +421,9 @@ age data: Dog + d="m 67.729044,86.224614 h 54.145186 l -0.045,31.672566 h 13.90067" + id="path19" + sodipodi:nodetypes="cccc" /> Date: Wed, 19 Feb 2025 10:54:11 -0500 Subject: [PATCH 15/15] One last change --- .../smart_pointers_owned_objects.svg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/comprehensive_rust_training/smart_pointers_owned_objects.svg b/images/comprehensive_rust_training/smart_pointers_owned_objects.svg index 8323cfeac..65190bc29 100644 --- a/images/comprehensive_rust_training/smart_pointers_owned_objects.svg +++ b/images/comprehensive_rust_training/smart_pointers_owned_objects.svg @@ -667,11 +667,11 @@ style="font-size:21.3333px;font-family:Calibri;-inkscape-font-specification:Calibri;text-align:start;writing-mode:lr-tb;direction:ltr;white-space:pre;shape-inside:url(#rect2-0-9-3-7);display:inline;fill:#000000;stroke:none;stroke-width:4.0252" x="22.526003" y="0"> ., 4, 4 + id="tspan24"> , 4, 4