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
a4bfc63d
Commit
a4bfc63d
authored
8 years ago
by
Carl Lerche
Browse files
Options
Downloads
Patches
Plain Diff
Tweak Sink / Source
parent
6f97d040
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/imp/buf/mod.rs
+19
-38
19 additions, 38 deletions
src/imp/buf/mod.rs
src/imp/bytes/rope.rs
+4
-4
4 additions, 4 deletions
src/imp/bytes/rope.rs
test/test_buf.rs
+1
-1
1 addition, 1 deletion
test/test_buf.rs
test/test_rope.rs
+2
-0
2 additions, 0 deletions
test/test_rope.rs
with
26 additions
and
43 deletions
src/imp/buf/mod.rs
+
19
−
38
View file @
a4bfc63d
...
...
@@ -27,10 +27,10 @@ pub trait Buf {
self
.remaining
()
>
0
}
fn
copy_to
<
S
:
Sink
>
(
&
mut
self
,
dst
:
S
)
->
usize
fn
copy_to
<
S
:
Sink
+
?
Sized
>
(
&
mut
self
,
dst
:
&
mut
S
)
->
usize
where
Self
:
Sized
{
let
rem
=
self
.remaining
();
dst
.
copy_from
(
self
);
dst
.
sink
(
self
);
rem
-
self
.remaining
()
}
...
...
@@ -206,7 +206,7 @@ pub trait MutBuf {
fn
copy_from
<
S
:
Source
>
(
&
mut
self
,
src
:
S
)
->
usize
where
Self
:
Sized
{
let
rem
=
self
.remaining
();
src
.
copy_to
(
self
);
src
.
source
(
self
);
rem
-
self
.remaining
()
}
...
...
@@ -440,36 +440,37 @@ impl<'a> IntoBuf for &'a () {
/// A value that writes bytes from itself into a `MutBuf`.
pub
trait
Source
{
fn
copy_to
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
);
/// Copy data from self into destination buffer
fn
source
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
);
}
impl
<
'a
>
Source
for
&
'a
[
u8
]
{
fn
copy_to
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
{
fn
source
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
{
buf
.write_slice
(
self
);
}
}
impl
Source
for
u8
{
fn
copy_to
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
{
fn
source
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
{
let
src
=
[
self
];
buf
.write_slice
(
&
src
);
}
}
impl
Source
for
Bytes
{
fn
copy_to
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
{
Source
::
copy_to
(
&
self
,
buf
);
fn
source
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
{
Source
::
source
(
&
self
,
buf
);
}
}
impl
<
'a
>
Source
for
&
'a
Bytes
{
fn
copy_to
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
{
Source
::
copy_to
(
self
.buf
(),
buf
);
fn
source
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
{
Source
::
source
(
&
mut
self
.buf
(),
buf
);
}
}
impl
<
T
:
Buf
>
Source
for
T
{
fn
copy_to
<
B
:
MutBuf
>
(
mut
self
,
buf
:
&
mut
B
)
{
impl
<
'a
,
T
:
Buf
>
Source
for
&
'a
mut
T
{
fn
source
<
B
:
MutBuf
>
(
mut
self
,
buf
:
&
mut
B
)
{
while
self
.has_remaining
()
&&
buf
.has_remaining
()
{
let
l
;
...
...
@@ -491,38 +492,18 @@ impl<T: Buf> Source for T {
}
pub
trait
Sink
{
fn
copy_from
<
B
:
Buf
>
(
self
,
buf
:
&
mut
B
);
fn
sink
<
B
:
Buf
>
(
&
mut
self
,
buf
:
&
mut
B
);
}
impl
<
'a
>
Sink
for
&
'a
mut
[
u8
]
{
fn
copy_from
<
B
:
Buf
>
(
self
,
buf
:
&
mut
B
)
{
impl
Sink
for
[
u8
]
{
fn
sink
<
B
:
Buf
>
(
&
mut
self
,
buf
:
&
mut
B
)
{
buf
.read_slice
(
self
);
}
}
impl
<
'a
>
Sink
for
&
'a
mut
Vec
<
u8
>
{
fn
copy_from
<
B
:
Buf
>
(
self
,
buf
:
&
mut
B
)
{
use
std
::
slice
;
self
.clear
();
let
rem
=
buf
.remaining
();
// Ensure that the vec is big enough
if
rem
>
self
.capacity
()
{
// current length is 0, so reserve completely
self
.reserve
(
rem
);
}
debug_assert!
(
rem
<=
self
.capacity
());
unsafe
{
{
let
dst
=
&
mut
self
[
..
];
buf
.read_slice
(
slice
::
from_raw_parts_mut
(
dst
.as_mut_ptr
(),
rem
));
}
self
.set_len
(
rem
);
}
impl
<
T
:
MutBuf
>
Sink
for
T
{
fn
sink
<
B
:
Buf
>
(
&
mut
self
,
buf
:
&
mut
B
)
{
Source
::
source
(
buf
,
self
)
}
}
...
...
This diff is collapsed.
Click to expand it.
src/imp/bytes/rope.rs
+
4
−
4
View file @
a4bfc63d
...
...
@@ -285,11 +285,11 @@ impl Node {
}
impl
<
'a
>
Source
for
&
'a
Node
{
fn
copy_to
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
{
fn
source
<
B
:
MutBuf
>
(
self
,
buf
:
&
mut
B
)
{
match
*
self
{
Node
::
Seq
(
ref
b
)
=>
b
.as_slice
()
.
copy_to
(
buf
),
Node
::
Small
(
ref
b
)
=>
b
.as_ref
()
.
copy_to
(
buf
),
Node
::
Rope
(
ref
b
)
=>
b
.buf
()
.
copy_to
(
buf
),
Node
::
Seq
(
ref
b
)
=>
b
.as_slice
()
.
source
(
buf
),
Node
::
Small
(
ref
b
)
=>
b
.as_ref
()
.
source
(
buf
),
Node
::
Rope
(
ref
b
)
=>
b
.buf
()
.
source
(
buf
),
Node
::
Empty
=>
unreachable!
(),
}
}
...
...
This diff is collapsed.
Click to expand it.
test/test_buf.rs
+
1
−
1
View file @
a4bfc63d
...
...
@@ -54,6 +54,6 @@ fn test_vec_sink_capacity() {
sink
.reserve
(
16
);
assert!
(
sink
.capacity
()
>=
16
,
"Capacity {} must be at least 16"
,
sink
.capacity
());
let
mut
source
=
Cursor
::
new
(
b"0123456789abcdef0123456789abcdef"
);
sink
.
copy_from
(
&
mut
source
);
sink
.
sink
(
&
mut
source
);
assert!
(
sink
.len
()
<=
sink
.capacity
(),
"Length {} must be less than or equal to capacity {}"
,
sink
.len
(),
sink
.capacity
());
}
This diff is collapsed.
Click to expand it.
test/test_rope.rs
+
2
−
0
View file @
a4bfc63d
...
...
@@ -38,12 +38,14 @@ pub fn test_rope_slice() {
let
left
=
bytes
.slice_to
(
250
);
assert_eq!
(
250
,
left
.len
());
dst
.clear
();
left
.buf
()
.copy_to
(
&
mut
dst
);
assert_eq!
(
dst
,
&
TEST_BYTES_1
[
..
250
]);
let
right
=
bytes
.slice_from
(
250
);
assert_eq!
(
TEST_BYTES_1
.len
()
-
250
,
right
.len
());
dst
.clear
();
right
.buf
()
.copy_to
(
&
mut
dst
);
// assert_eq!(dst, &TEST_BYTES_1[250..]);
}
...
...
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