Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rust_seminar_generators
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Jost Hermann Triller
rust_seminar_generators
Commits
94aaca4e
Commit
94aaca4e
authored
1 year ago
by
Tsoj Tsoj
Browse files
Options
Downloads
Patches
Plain Diff
Removed stupid comments
parent
47c0c639
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+13
-24
13 additions, 24 deletions
src/main.rs
with
13 additions
and
24 deletions
src/main.rs
+
13
−
24
View file @
94aaca4e
...
...
@@ -22,21 +22,20 @@ extern "C" fn context_function<ReturnValue>(t: Transfer) -> ! {
((
*
generator_ptr
)
.f
)(
&
mut
(
*
generator_ptr
));
}
loop
{
compiler_fence
(
Ordering
::
AcqRel
);
unsafe
{
(
*
generator_ptr
)
.is_finished
=
true
;
(
*
generator_ptr
)
.t
=
Some
(
(
*
generator_ptr
)
.t
.take
()
.unwrap
()
.context
.resume
(
generator_ptr
as
usize
),
);
}
compiler_fence
(
Ordering
::
AcqRel
);
compiler_fence
(
Ordering
::
AcqRel
);
unsafe
{
(
*
generator_ptr
)
.is_finished
=
true
;
(
*
generator_ptr
)
.t
=
Some
(
(
*
generator_ptr
)
.t
.take
()
.unwrap
()
.context
.resume
(
generator_ptr
as
usize
),
);
}
compiler_fence
(
Ordering
::
AcqRel
);
panic!
(
"We should be finished by now ..."
)
}
impl
<
ReturnValue
>
Generator
<
ReturnValue
>
{
...
...
@@ -65,20 +64,10 @@ impl<ReturnValue> Generator<ReturnValue> {
}
}
// Implement `Iterator` for `Fibonacci`.
// The `Iterator` trait only requires a method to be defined for the `next` element.
impl
<
ReturnValue
>
Iterator
for
Generator
<
ReturnValue
>
{
// We can refer to this type using Self::Item
type
Item
=
ReturnValue
;
// Here, we define the sequence using `.curr` and `.next`.
// The return type is `Option<T>`:
// * When the `Iterator` is finished, `None` is returned.
// * Otherwise, the next value is wrapped in `Some` and returned.
// We use Self::Item in the return type, so we can change
// the type without having to update the function signatures.
fn
next
(
&
mut
self
)
->
Option
<
Self
::
Item
>
{
// Allocate a Context on the stack.
let
generator_ptr
=
self
as
*
mut
Generator
<
ReturnValue
>
;
unsafe
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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