Skip to content
Snippets Groups Projects
Commit 78929b2d authored by orestis.malaspin's avatar orestis.malaspin
Browse files

ajouts divers

parent df88dd6d
No related branches found
No related tags found
No related merge requests found
Pipeline #
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "make",
"type": "shell",
"command": "make",
"group": {
"kind": "build",
"isDefault": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
}
}
]
}
\ No newline at end of file
fn do_something(_notebook: Vec<&str>) {
// Do something with the notebook
}
fn do_something(_notebook: Vec<&str>) { // _notebook prend l'ownership
// Do something with the library
} // _notebook est détruit et ses données aussi
fn main() {
let mut notebook = Vec::new(); // par défaut notebook est immutable
notebook.push("Il fait beau.");
notebook.push("Lea oiseaux chantent.");
notebook.push("Les oiseaux chantent.");
do_something(notebook); // ownership transféré à do_something
// do_something(notebook); // redo something
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -24,9 +24,9 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.8101934"
inkscape:cx="458.65331"
inkscape:cy="108.243"
inkscape:zoom="1.28"
inkscape:cx="413.47675"
inkscape:cy="147.32168"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="true"
......@@ -387,7 +387,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
......@@ -559,54 +559,6 @@
</g>
</g>
</g>
<g
style="fill:#000000"
transform="translate(-54.822849,-98.973333)"
ns1:textextver="0.8"
ns1:converter="pdf2svg"
ns1:text="$4$"
ns1:preamble="/home/malaspor/.config/inkscape/extensions/default_packages.tex"
ns1:scale="1.0"
id="g4809-4">
<g
style="fill:#000000"
id="g4807-5">
<g
style="fill:#000000;fill-opacity:1"
id="g4805-0">
<path
inkscape:connector-curvature="0"
style="stroke:none"
d="m 2.9375,-1.640625 v 0.859375 c 0,0.359375 -0.03125,0.46875 -0.765625,0.46875 H 1.96875 V 0 C 2.375,-0.03125 2.890625,-0.03125 3.3125,-0.03125 c 0.421875,0 0.9375,0 1.359375,0.03125 v -0.3125 h -0.21875 c -0.734375,0 -0.75,-0.109375 -0.75,-0.46875 V -1.640625 H 4.6875 v -0.3125 H 3.703125 v -4.53125 c 0,-0.203125 0,-0.265625 -0.171875,-0.265625 -0.078125,0 -0.109375,0 -0.1875,0.125 l -3.0625,4.671875 v 0.3125 z m 0.046875,-0.3125 H 0.5625 l 2.421875,-3.71875 z m 0,0"
transform="translate(148.712,134.765)"
id="path4803-3" />
</g>
</g>
</g>
<g
style="fill:#000000"
transform="translate(-33.330513,-98.973333)"
ns1:textextver="0.8"
ns1:converter="pdf2svg"
ns1:text="$4$"
ns1:preamble="/home/malaspor/.config/inkscape/extensions/default_packages.tex"
ns1:scale="1.0"
id="g4809-6">
<g
style="fill:#000000"
id="g4807-1">
<g
style="fill:#000000;fill-opacity:1"
id="g4805-06">
<path
inkscape:connector-curvature="0"
style="stroke:none"
d="m 2.9375,-1.640625 v 0.859375 c 0,0.359375 -0.03125,0.46875 -0.765625,0.46875 H 1.96875 V 0 C 2.375,-0.03125 2.890625,-0.03125 3.3125,-0.03125 c 0.421875,0 0.9375,0 1.359375,0.03125 v -0.3125 h -0.21875 c -0.734375,0 -0.75,-0.109375 -0.75,-0.46875 V -1.640625 H 4.6875 v -0.3125 H 3.703125 v -4.53125 c 0,-0.203125 0,-0.265625 -0.171875,-0.265625 -0.078125,0 -0.109375,0 -0.1875,0.125 l -3.0625,4.671875 v 0.3125 z m 0.046875,-0.3125 H 0.5625 l 2.421875,-3.71875 z m 0,0"
transform="translate(148.712,134.765)"
id="path4803-32" />
</g>
</g>
</g>
<g
transform="matrix(0.56239016,0,0,0.56239016,25.564409,-58.088699)"
ns1:textextver="0.8"
......@@ -1076,5 +1028,79 @@
</g>
</g>
</g>
<g
transform="matrix(1.000000,0.000000,0.000000,-1.000000,-56.488897,166.650417)"
ns1:version="0.8.1"
ns1:texconverter="pdflatex"
ns1:pdfconverter="pdf2svg"
ns1:text="..."
ns1:preamble="/usr/share/inkscape/extensions/default_packages.tex"
ns1:scale="2.83464566935"
ns1:alignment="middle center"
inkscapeversion="0.92.2"
ns1:jacobian_sqrt="1.0"
style="fill:#000000"
id="g1301">
<g
id="g1299"
style="fill:#000000">
<g
style="fill-opacity:1;fill:#000000"
id="g1297">
<path
style="stroke:none;stroke-width:0;fill:#000000"
d="M 1.90625 -0.53125 C 1.90625 -0.8125 1.671875 -1.0625 1.390625 -1.0625 C 1.09375 -1.0625 0.859375 -0.8125 0.859375 -0.53125 C 0.859375 -0.234375 1.09375 0 1.390625 0 C 1.671875 0 1.90625 -0.234375 1.90625 -0.53125 Z M 1.90625 -0.53125 "
transform="translate(148.712,134.765)"
id="path1291" />
<path
style="stroke:none;stroke-width:0;fill:#000000"
d="M 1.90625 -0.53125 C 1.90625 -0.8125 1.671875 -1.0625 1.390625 -1.0625 C 1.09375 -1.0625 0.859375 -0.8125 0.859375 -0.53125 C 0.859375 -0.234375 1.09375 0 1.390625 0 C 1.671875 0 1.90625 -0.234375 1.90625 -0.53125 Z M 1.90625 -0.53125 "
transform="translate(151.47961,134.765)"
id="path1293" />
<path
style="stroke:none;stroke-width:0;fill:#000000"
d="M 1.90625 -0.53125 C 1.90625 -0.8125 1.671875 -1.0625 1.390625 -1.0625 C 1.09375 -1.0625 0.859375 -0.8125 0.859375 -0.53125 C 0.859375 -0.234375 1.09375 0 1.390625 0 C 1.671875 0 1.90625 -0.234375 1.90625 -0.53125 Z M 1.90625 -0.53125 "
transform="translate(154.247221,134.765)"
id="path1295" />
</g>
</g>
</g>
<g
id="g1646"
style="fill:#000000"
ns1:jacobian_sqrt="1.0"
inkscapeversion="0.92.2"
ns1:alignment="middle center"
ns1:scale="2.83464566935"
ns1:preamble="/usr/share/inkscape/extensions/default_packages.tex"
ns1:text="..."
ns1:pdfconverter="pdf2svg"
ns1:texconverter="pdflatex"
ns1:version="0.8.1"
transform="matrix(1.000000,0.000000,0.000000,-1.000000,-34.996561,166.650417)">
<g
style="fill:#000000"
id="g1644">
<g
id="g1642"
style="fill-opacity:1;fill:#000000">
<path
id="path1636"
transform="translate(148.712,134.765)"
d="M 1.90625 -0.53125 C 1.90625 -0.8125 1.671875 -1.0625 1.390625 -1.0625 C 1.09375 -1.0625 0.859375 -0.8125 0.859375 -0.53125 C 0.859375 -0.234375 1.09375 0 1.390625 0 C 1.671875 0 1.90625 -0.234375 1.90625 -0.53125 Z M 1.90625 -0.53125 "
style="stroke:none;stroke-width:0;fill:#000000" />
<path
id="path1638"
transform="translate(151.47961,134.765)"
d="M 1.90625 -0.53125 C 1.90625 -0.8125 1.671875 -1.0625 1.390625 -1.0625 C 1.09375 -1.0625 0.859375 -0.8125 0.859375 -0.53125 C 0.859375 -0.234375 1.09375 0 1.390625 0 C 1.671875 0 1.90625 -0.234375 1.90625 -0.53125 Z M 1.90625 -0.53125 "
style="stroke:none;stroke-width:0;fill:#000000" />
<path
id="path1640"
transform="translate(154.247221,134.765)"
d="M 1.90625 -0.53125 C 1.90625 -0.8125 1.671875 -1.0625 1.390625 -1.0625 C 1.09375 -1.0625 0.859375 -0.8125 0.859375 -0.53125 C 0.859375 -0.234375 1.09375 0 1.390625 0 C 1.671875 0 1.90625 -0.234375 1.90625 -0.53125 Z M 1.90625 -0.53125 "
style="stroke:none;stroke-width:0;fill:#000000" />
</g>
</g>
</g>
</g>
</svg>
......@@ -127,35 +127,48 @@ Quel est le problème dans ce code?
# Sûreté mémoire en Rust
## Ownership (1/N)
## Ownership (1/1)
- Quand on est **propriétaire** des données, on peut faire ce qu'on veut avec:
1. Les lire.
2. Les modifier.
3. Les donner à quelqu'un d'autre.
## Ownership (2/N)
## Ownership (2/2)
![Comme avec un cahier. Source [Wikipedia](https://upload.wikimedia.org/wikipedia/commons/9/9f/Se%C5%A1ity.JPG)](https://upload.wikimedia.org/wikipedia/commons/9/9f/Se%C5%A1ity.JPG){#fig:mem_vec_str width=50%}
## Ownership en pratique
<pre><code data-trim="hljs rust" class="lang-rust">
fn do_something(library: Vec<&str>) {
fn do_something(_notebook: Vec<&str>) { // _notebook prend l'ownership
// Do something with the library
}
} // _notebook est détruit et ses données aussi
fn main() {
let mut notebook = Vec::new(); // par défaut notebook est immutable
library.push("Il fait beau.");
library.push("Les oiseaux chantent.");
notebook.push("Il fait beau.");
notebook.push("Les oiseaux chantent.");
do_something(library); // ownership transféré à do_something
// do_something(library); // redo something
do_something(notebook); // ownership transféré à do_something
// do_something(notebook); // redo something
}
</code></pre>
## Ownership en pratique
Ce qui se passe en mémoire:
![](figs/mem_vec_ownership.svg){#fig:mem_vec_ownership width=45%}![](figs/mem_vec_ownership_move.svg){#fig:mem_vec_ownership_move width=45%}
![](figs/mem_vec_ownership_dest.svg){#fig:mem_vec_ownership_move width=45%}
. . .
**`notebook` est détruit à la fin de `do_something` et ne peut plus être réutilisé**
<!-- - `vector` et `string` sont alignés en mémoire.
- références "light".
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment