Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
lpc1769
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
lpc1769
Commits
70e24369
Commit
70e24369
authored
Sep 22, 2017
by
Jonas Schievink
Browse files
Options
Downloads
Patches
Plain Diff
Simplify iterator usage
parent
b1777ebd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
macros/src/trans.rs
+10
-17
10 additions, 17 deletions
macros/src/trans.rs
with
10 additions
and
17 deletions
macros/src/trans.rs
+
10
−
17
View file @
70e24369
...
@@ -160,20 +160,15 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
...
@@ -160,20 +160,15 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
let
mut
ret
=
None
;
let
mut
ret
=
None
;
let
mut
mod_items
=
vec!
[];
let
mut
mod_items
=
vec!
[];
// Write resources usable by `init`, if any
let
(
init_resources
,
late_resources
):
(
Vec
<
_
>
,
Vec
<
_
>
)
=
app
.resources
.iter
()
.partition
(|
&
(
_
,
res
)|
res
.expr
.is_some
());
if
!
init_resources
.is_empty
()
{
// Are there any resources that have an initializer? Those can be used by `init`.
let
has_initialized_resources
=
app
.resources
.iter
()
.find
(|
&
(
_
,
res
)|
res
.expr
.is_some
())
.is_some
();
if
has_initialized_resources
{
let
mut
fields
=
vec!
[];
let
mut
fields
=
vec!
[];
let
mut
lifetime
=
None
;
let
mut
lifetime
=
None
;
let
mut
rexprs
=
vec!
[];
let
mut
rexprs
=
vec!
[];
for
(
name
,
resource
)
in
app
.resources
.iter
()
for
(
name
,
resource
)
in
init_resources
{
.filter
(|
&
(
_
,
res
)|
res
.expr
.is_some
())
{
let
_name
=
Ident
::
new
(
format!
(
"_{}"
,
name
.as_ref
()));
let
_name
=
Ident
::
new
(
format!
(
"_{}"
,
name
.as_ref
()));
lifetime
=
Some
(
quote!
(
'a
));
lifetime
=
Some
(
quote!
(
'a
));
...
@@ -213,17 +208,15 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
...
@@ -213,17 +208,15 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
exprs
.push
(
quote!
(
init
::
Resources
::
new
()));
exprs
.push
(
quote!
(
init
::
Resources
::
new
()));
}
}
let
mut
late_resources
=
vec!
[];
// Initialization statements for late resources
let
has_late_resources
=
app
.resources
.iter
()
let
mut
late_resource_init
=
vec!
[];
.find
(|
&
(
_
,
res
)|
res
.expr
.is_none
())
.is_some
();
if
has_
late_resources
{
if
!
late_resources
.is_empty
()
{
// `init` must initialize and return resources
// `init` must initialize and return resources
let
mut
fields
=
vec!
[];
let
mut
fields
=
vec!
[];
for
(
name
,
resource
)
in
app
.resources
.iter
()
for
(
name
,
resource
)
in
late_resources
{
.filter
(|
&
(
_
,
res
)|
res
.expr
.is_none
())
{
let
_name
=
Ident
::
new
(
format!
(
"_{}"
,
name
.as_ref
()));
let
_name
=
Ident
::
new
(
format!
(
"_{}"
,
name
.as_ref
()));
let
ty
=
&
resource
.ty
;
let
ty
=
&
resource
.ty
;
...
@@ -232,7 +225,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
...
@@ -232,7 +225,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
pub
#
name
:
#
ty
,
pub
#
name
:
#
ty
,
});
});
late_resource
s
.push
(
quote!
{
late_resource
_init
.push
(
quote!
{
#
_name
=
#
krate
::
UntaggedOption
{
some
:
_late_resources
.#
name
};
#
_name
=
#
krate
::
UntaggedOption
{
some
:
_late_resources
.#
name
};
});
});
}
}
...
@@ -316,7 +309,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
...
@@ -316,7 +309,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
#
krate
::
atomic
(
unsafe
{
&
mut
#
krate
::
Threshold
::
new
(
0
)
},
|
_t
|
unsafe
{
#
krate
::
atomic
(
unsafe
{
&
mut
#
krate
::
Threshold
::
new
(
0
)
},
|
_t
|
unsafe
{
let
_late_resources
=
init
(
#
(
#
exprs
,)
*
);
let
_late_resources
=
init
(
#
(
#
exprs
,)
*
);
#
(
#
late_resource
s
)
*
#
(
#
late_resource
_init
)
*
#
(
#
exceptions
)
*
#
(
#
exceptions
)
*
#
(
#
interrupts
)
*
#
(
#
interrupts
)
*
...
...
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