Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
timber
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
Per Lindgren
timber
Commits
878251d3
Commit
878251d3
authored
7 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
compiles
parent
4d7a9016
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
examples/vec_deque.rs
+19
-29
19 additions, 29 deletions
examples/vec_deque.rs
with
19 additions
and
29 deletions
examples/vec_deque.rs
+
19
−
29
View file @
878251d3
...
...
@@ -79,30 +79,23 @@ trait Dispatch {
fn
dispatch
(
&
mut
self
);
}
// struct MsgQ<'a, T>(VecDeque<&'a Mutex<T>>)
// where
// T: 'a + Dispatch;
// impl<'a, T> Dispatch for MsgQ<'a, T>
// where
// T: 'a + Dispatch,
// {
// fn dispatch(&mut self) {}
// }
// impl<'a, T> Dispatch for &'a Vec<Mutex<T>> {
// fn dispatch(&mut self) {}
// }
struct
MsgQ
<
'a
>
(
VecDeque
<&
'a
mut
Dispatch
>
);
struct
MsgQ
<
'a
>
(
VecDeque
<&
'a
Dispatch
>
);
impl
<
'a
>
Dispatch
for
MsgQ
<
'a
>
{
fn
dispatch
(
&
mut
self
)
{
println!
(
"MsgQ Dispatch"
);
// impl<'a, T> Dispatch for MsgQ<'a, T> {
//
fn dispatch(&mut self) {
}
//
}
struct
Msg
<
T
>
(
Mutex
<
T
>
,
Box
<
FnMut
(
T
)
->
()
>
);
self
.0
.pop_front
()
.unwrap
()
.dispatch
();
}
}
struct
Msg
<
T
>
(
Mutex
<
T
>
,
Box
<
FnMut
(
&
mut
T
)
->
()
>
);
impl
<
T
>
Dispatch
for
Msg
<
T
>
{
fn
dispatch
(
&
mut
self
)
{}
fn
dispatch
(
&
mut
self
)
{
println!
(
"Msg Dispatch"
);
let
mut
o
=
self
.0
.lock
()
.unwrap
();
self
.1
(
&
mut
*
o
);
}
}
impl
<
T
>
Dispatch
for
Mutex
<
T
>
{
...
...
@@ -145,21 +138,18 @@ fn main() {
)));
let
m
=
Mutex
::
new
(
0
);
let
m2
=
Mutex
::
new
(
0.0
);
let
mut
q
=
MsgQ
{
0
:
VecDeque
::
new
(),
};
q
.0
.push_back
(
&
m
);
q
.0
.push_back
(
&
m2
);
let
mut
q
=
MsgQ
{
0
:
VecDeque
::
new
()
};
let
c1
=
|
o
:
&
mut
i32
|
println!
(
"hello {}"
,
o
);
let
c1
=
|
o
|
println!
(
"hello {}"
,
o
);
let
msg
=
Msg
{
let
mut
msg
=
Msg
{
0
:
m
,
1
:
Box
::
new
(
c1
),
};
q
.0
.dispatch
();
q
.0
.push_back
(
&
mut
msg
);
q
.dispatch
();
//q.0.push_back(&(m, c1));
...
...
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