Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
array-debug
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
array-debug
Commits
4f850f52
Commit
4f850f52
authored
6 years ago
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
more examples
parent
da378c2a
Branches
master
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/example3.rs
+29
-16
29 additions, 16 deletions
examples/example3.rs
src/lib.rs
+2
-2
2 additions, 2 deletions
src/lib.rs
with
31 additions
and
18 deletions
examples/example3.rs
+
29
−
16
View file @
4f850f52
extern
crate
array_debug
;
use
array_debug
::
ArrayDebug
;
use
core
::
ops
::
{
Deref
,
DerefMut
}
;
use
core
::
ops
::
Deref
;
#[derive(Debug)]
#[repr(C)]
...
...
@@ -19,48 +19,61 @@ struct RegisterBlockNative {
}
fn
main
()
{
let
mut
r
=
RegisterBlockDebug
{
let
mut
r
d
=
RegisterBlockDebug
{
primitive
:
7
,
small
:
ArrayDebug
::
new
([
1
,
3
,
4
]),
big
:
ArrayDebug
::
new
([
8
;
44
]),
};
r
.small
[
1
]
=
7
;
println!
(
"r :{:?}"
,
r
);
r
d
.small
[
1
]
=
7
;
println!
(
"r
d
:{:?}"
,
r
d
);
// auto deref coersion of ArrayDebug
let
t
:
&
[
u32
]
=
&
r
.small
;
let
t
:
&
[
u32
]
=
&
r
d
.big
;
print!
(
"rd.big ["
);
for
i
in
t
{
print
ln
!
(
"{}"
,
i
);
print!
(
"{}
,
"
,
i
);
}
println!
(
"]"
);
// // deref goes too far, [u32] is not an iterator
// for i in *rd.small {
// println!("{}", i);
// }
// `&array_debug::ArrayDebug<[u32; 3], u32>` is not an iterator
// for i in &rd.small {
// println!("{}", i);
// }
// explicit deref required
for
i
in
*
r
.small
{
for
i
in
&*
rd
.small
{
println!
(
"{}"
,
i
);
}
// explicit deref
required
for
i
in
r
.small
.deref
()
{
// explicit deref
works
for
i
in
r
d
.small
.deref
()
{
println!
(
"{}"
,
i
);
}
for
i
in
r
.small
.iter
()
{
println!
(
"{}"
,
i
);
// works, and is consistent with the native type
print!
(
"rd.small ["
);
for
i
in
rd
.small
.iter
()
{
print!
(
"{}"
,
i
);
}
println!
(
"]"
);
let
r
=
RegisterBlockNative
{
let
r
n
=
RegisterBlockNative
{
primitive
:
7
,
small
:
[
1
,
3
,
4
],
big
:
[
8
;
44
],
};
for
i
in
&
r
.small
{
for
i
in
&
r
n
.small
{
println!
(
"{}"
,
i
);
}
for
i
in
r
.small
.iter
()
{
for
i
in
r
n
.small
.iter
()
{
println!
(
"{}"
,
i
);
}
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
2
−
2
View file @
4f850f52
...
...
@@ -26,7 +26,7 @@ where
{
type
Target
=
[
T
];
fn
deref
(
&
self
)
->
&
Self
::
Target
{
fn
deref
(
&
self
)
->
&
[
T
]
{
&
self
.0
}
}
...
...
@@ -36,7 +36,7 @@ where
A
:
Unsize
<
[
T
]
>
,
T
:
fmt
::
Debug
,
{
fn
deref_mut
(
&
mut
self
)
->
&
mut
Self
::
Target
{
fn
deref_mut
(
&
mut
self
)
->
&
mut
[
T
]
{
&
mut
self
.0
}
}
...
...
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