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
67d34a0d
There was a problem fetching the pipeline summary.
Commit
67d34a0d
authored
6 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
fonctions de base terminé
parent
bcd6414c
No related branches found
No related tags found
No related merge requests found
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fonctions.md
+31
-4
31 additions, 4 deletions
fonctions.md
with
31 additions
and
4 deletions
fonctions.md
+
31
−
4
View file @
67d34a0d
...
@@ -71,8 +71,9 @@ fn main() {
...
@@ -71,8 +71,9 @@ fn main() {
-
Les fonctions s'écrivent en
*snake_case*
(le compilateur vous avertiras...).
-
Les fonctions s'écrivent en
*snake_case*
(le compilateur vous avertiras...).
-
La définition d'une fonction commence par un
`fn`
{.rust}.
-
La définition d'une fonction commence par un
`fn`
{.rust}.
-
La définition des fonctions peut se faire avant ou après l'endroit où elle est appelée.
-
La définition des fonctions peut se faire avant ou après l'endroit où elle est appelée.
-
Une fonction contient des instructions et se termine parfois avec une expression.
<pre><code data-trim="hljs rust" class="lang-rust">
<pre><code
data-trim=
"hljs rust"
class=
"lang-rust"
>
fn main() {
fn main() {
println!("La fonction main est une fonction.");
println!("La fonction main est une fonction.");
...
@@ -82,10 +83,36 @@ fn main() {
...
@@ -82,10 +83,36 @@ fn main() {
fn fonction_fonction() {
fn fonction_fonction() {
println!("La fonction fonction_fonction est une fonction.");
println!("La fonction fonction_fonction est une fonction.");
}
}
</code></pre>
</code></pre>
## Paramètres de fonctions
## Paramètres de fonctions
-
Une fonction peut prendre des arguments séparés par des
`,`
{.rust}.
-
Une fonction peut prendre des arguments séparés par des
"
`,`
{.rust}
"
.
-
Le type des arguments doit toujours être explicitement déclaré.
-
Le type des arguments doit toujours être explicitement déclaré.
-
\ No newline at end of file
<pre><code data-trim="hljs rust" class="lang-rust">
fn main() {
affiche_entier(1024);
}
fn affiche_entier(x: i32) {
println!("Affiche l'entier {}.", x);
}
</code></pre>
## Valeur de retour de fonctions
-
On déclare le type de retour d'une fonction avec
`-> Type`
{.rust}.
<pre><code data-trim="hljs rust" class="lang-rust">
fn main() {
println!("La réponse est {}.", la_reponse());
}
fn la_reponse() -> i32 {
42
}
</code></pre>
-
**Important:**
La valeur de retour d'une fonction n'est pas suivie d'un "
`;`
{.rust}".
-
Les instructions ne retournent pas de valeur et sont représentées par le type
`()`
{.rust} (le type vide).
\ No newline at end of file
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