Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
rust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orestis.malaspin
rust
Commits
60da7090
Commit
60da7090
authored
6 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
added borrow example
parent
b606ad2b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
presentation/codes/borrowing/Cargo.toml
+7
-0
7 additions, 0 deletions
presentation/codes/borrowing/Cargo.toml
presentation/codes/borrowing/src/main.rs
+19
-0
19 additions, 0 deletions
presentation/codes/borrowing/src/main.rs
with
26 additions
and
0 deletions
presentation/codes/borrowing/Cargo.toml
0 → 100644
+
7
−
0
View file @
60da7090
[package]
name
=
"borrowing"
version
=
"0.1.0"
authors
=
[
"Orestis Malaspinas <orestis.malaspinas@hesge.ch>"
]
edition
=
"2018"
[dependencies]
This diff is collapsed.
Click to expand it.
presentation/codes/borrowing/src/main.rs
0 → 100644
+
19
−
0
View file @
60da7090
fn
borrow
(
_notebook
:
&
Vec
<&
str
>
)
{
// _notebook prend l'ownership de la référence vers un Vec
// on peut lire les données contenues dans notebook
}
// la référence est détruite, les données sont rendues à notebook
fn
main
()
{
let
mut
notebook
=
Vec
::
new
();
// par défaut notebook est immutable
notebook
.push
(
"Il fait beau."
);
notebook
.push
(
"Les oiseaux chantent."
);
borrow
(
&
notebook
);
// on crée une référence et on la passe à borrow
borrow
(
&
notebook
);
// on peut réutiliser notebook
{
let
n
=
&
notebook
;
borrow
(
n
);
borrow
(
&
notebook
);
}
// la référence n est détruite
borrow
(
&
notebook
);
// on peut réutiliser notebook
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment