Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
erode
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Per Lindgren
erode
Commits
521c375e
Commit
521c375e
authored
4 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
examples from student repo
parent
7e92be3d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/w1_2.rs
+62
-0
62 additions, 0 deletions
examples/w1_2.rs
with
62 additions
and
0 deletions
examples/w1_2.rs
0 → 100644
+
62
−
0
View file @
521c375e
// a function taking no arguments returning the unit type
fn
a
()
->
()
{
let
_a
:
i32
=
5
;
// this returns a unit type
}
// a function taking two i32 arguments returning the i32 type
fn
b
(
_x
:
i32
,
_y
:
i32
)
->
i32
{
3
// this returns 3 (as i32)
}
// a function taking two i32 arguments returning the i32 type
// with some let statements
fn
c
(
x
:
i32
,
y
:
i32
)
->
i32
{
let
a
:
i32
=
5
;
let
b
:
i32
=
x
+
y
;
// this will be an infix operator "+""
-
a
-
(
-
b
)
*
y
// here we have prefix operator "-"
}
// More advanced statements
// a function taking two bool arguments returning the bool type
// with some let statements and function calls
fn
a
(
x
:
bool
,
y
:
bool
)
->
bool
{
if
x
&&
y
{
let
a
:
bool
=
true
;
y
||
a
}
else
{
x
&&
false
}
}
// a function taking two bool arguments returning the i32 type
// with some let statements and function calls
fn
b
(
x
:
bool
,
y
:
bool
)
->
i32
{
let
a
:
bool
=
a
(
x
,
y
||
false
);
let
mut
b
:
i32
=
0
;
if
a
&&
y
{
let
a
:
bool
=
true
;
// shadowing
if
y
||
a
{
b
=
b
+
1
;
};
}
else
{
if
!
(
x
&&
false
)
{
b
=
b
-
1
;
}
};
b
+
3
}
// a function taking two bool arguments returning the i32 type
// while
fn
c
(
x
:
bool
,
y
:
bool
)
->
i32
{
let
mut
b
:
i32
=
0
;
let
mut
c
:
i32
=
1
;
while
(
b
<
10
)
{
c
=
c
*
2
;
};
c
}
fn
main
()
{}
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