Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bytes-sgx
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
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Markus Becker
bytes-sgx
Commits
83680dda
Commit
83680dda
authored
10 years ago
by
Carl Lerche
Browse files
Options
Downloads
Patches
Plain Diff
Implement Source for std::io::Read
parent
bb122711
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/lib.rs
+14
-9
14 additions, 9 deletions
src/lib.rs
test/test.rs
+2
-0
2 additions, 0 deletions
test/test.rs
test/test_buf_fill.rs
+43
-0
43 additions, 0 deletions
test/test_buf_fill.rs
with
59 additions
and
9 deletions
src/lib.rs
+
14
−
9
View file @
83680dda
...
...
@@ -444,19 +444,24 @@ impl<'a> Source for &'a Bytes {
}
}
impl
<
'a
>
Source
for
&
'a
mut
(
io
::
Read
+
'a
)
{
impl
<
'a
,
R
:
io
::
Read
+
'a
>
Source
for
&
'a
mut
R
{
type
Error
=
io
::
Error
;
fn
fill
<
B
:
MutBuf
>
(
self
,
_buf
:
&
mut
B
)
->
Result
<
usize
,
io
::
Error
>
{
unimplemented!
();
}
}
fn
fill
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
->
Result
<
usize
,
io
::
Error
>
{
let
mut
cnt
=
0
;
impl
<
'a
>
Source
for
&
'a
mut
(
Iterator
<
Item
=
u8
>+
'a
)
{
type
Error
=
BufError
;
while
buf
.has_remaining
()
{
let
i
=
try
!
(
self
.read
(
buf
.mut_bytes
()));
if
i
==
0
{
break
;
}
buf
.advance
(
i
);
cnt
+=
i
;
}
fn
fill
<
B
:
MutBuf
>
(
self
,
_buf
:
&
mut
B
)
->
Result
<
usize
,
BufError
>
{
unimplemented!
();
Ok
(
cnt
)
}
}
...
...
This diff is collapsed.
Click to expand it.
test/test.rs
+
2
−
0
View file @
83680dda
...
...
@@ -5,6 +5,8 @@ use rand::random;
extern
crate
bytes
;
extern
crate
rand
;
mod
test_buf
;
mod
test_buf_fill
;
mod
test_byte_buf
;
mod
test_bytes
;
mod
test_rope
;
...
...
This diff is collapsed.
Click to expand it.
test/test_buf_fill.rs
0 → 100644
+
43
−
0
View file @
83680dda
use
bytes
::
*
;
use
std
::
io
;
#[test]
pub
fn
test_filling_buf_from_reader
()
{
let
mut
reader
=
chunks
(
vec!
[
b"foo"
,
b"bar"
,
b"baz"
]);
let
mut
buf
=
ByteBuf
::
mut_with_capacity
(
1024
);
assert_eq!
(
9
,
buf
.write
(
&
mut
reader
)
.unwrap
());
assert_eq!
(
b"foobarbaz"
.to_bytes
(),
buf
.flip
()
.to_bytes
());
}
fn
chunks
(
chunks
:
Vec
<&
'static
[
u8
]
>
)
->
Chunked
{
Chunked
{
chunks
:
chunks
}
}
struct
Chunked
{
chunks
:
Vec
<&
'static
[
u8
]
>
,
}
impl
io
::
Read
for
Chunked
{
fn
read
(
&
mut
self
,
dst
:
&
mut
[
u8
])
->
io
::
Result
<
usize
>
{
use
std
::
cmp
;
use
std
::
slice
::
bytes
;
if
self
.chunks
.is_empty
()
{
return
Ok
(
0
);
}
let
src
=
self
.chunks
[
0
];
let
len
=
cmp
::
min
(
src
.len
(),
dst
.len
());
bytes
::
copy_memory
(
&
mut
dst
[
..
len
],
&
src
[
..
len
]);
if
len
<
src
.len
()
{
self
.chunks
[
0
]
=
&
src
[
len
..
];
}
else
{
self
.chunks
.remove
(
0
);
}
Ok
(
len
)
}
}
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