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
531c7765
Commit
531c7765
authored
9 years ago
by
Carl Lerche
Browse files
Options
Downloads
Plain Diff
Merge branch 'v0.2.x'
parents
b4abd143
ed087be8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/buf/mod.rs
+2
-0
2 additions, 0 deletions
src/buf/mod.rs
src/buf/take.rs
+79
-0
79 additions, 0 deletions
src/buf/take.rs
src/lib.rs
+2
-1
2 additions, 1 deletion
src/lib.rs
test/test.rs
+1
-0
1 addition, 0 deletions
test/test.rs
test/test_buf_take.rs
+12
-0
12 additions, 0 deletions
test/test_buf_take.rs
with
96 additions
and
1 deletion
src/buf/mod.rs
+
2
−
0
View file @
531c7765
...
...
@@ -3,10 +3,12 @@ mod ring;
mod
sink
;
mod
slice
;
mod
source
;
mod
take
;
pub
use
self
::
byte
::{
ByteBuf
,
MutByteBuf
,
ROByteBuf
};
pub
use
self
::
ring
::
RingBuf
;
pub
use
self
::
slice
::{
SliceBuf
,
MutSliceBuf
};
pub
use
self
::
take
::
Take
;
use
{
BufError
,
RopeBuf
};
use
std
::{
cmp
,
fmt
,
io
,
ptr
,
usize
};
...
...
This diff is collapsed.
Click to expand it.
src/buf/take.rs
0 → 100644
+
79
−
0
View file @
531c7765
use
buf
::{
Buf
,
MutBuf
};
use
std
::{
cmp
,
io
};
#[derive(Debug)]
pub
struct
Take
<
T
>
{
inner
:
T
,
limit
:
usize
,
}
impl
<
T
>
Take
<
T
>
{
pub
fn
new
(
inner
:
T
,
limit
:
usize
)
->
Take
<
T
>
{
Take
{
inner
:
inner
,
limit
:
limit
,
}
}
pub
fn
into_inner
(
self
)
->
T
{
self
.inner
}
pub
fn
get_ref
(
&
self
)
->
&
T
{
&
self
.inner
}
pub
fn
get_mut
(
&
mut
self
)
->
&
mut
T
{
&
mut
self
.inner
}
pub
fn
limit
(
&
self
)
->
usize
{
self
.limit
}
pub
fn
set_limit
(
&
mut
self
,
lim
:
usize
)
{
self
.limit
=
lim
}
}
impl
<
T
:
Buf
>
Buf
for
Take
<
T
>
{
fn
remaining
(
&
self
)
->
usize
{
cmp
::
min
(
self
.inner
.remaining
(),
self
.limit
)
}
fn
bytes
<
'a
>
(
&
'a
self
)
->
&
'a
[
u8
]
{
&
self
.inner
.bytes
()[
..
self
.limit
]
}
fn
advance
(
&
mut
self
,
cnt
:
usize
)
{
let
cnt
=
cmp
::
min
(
cnt
,
self
.limit
);
self
.limit
-=
cnt
;
self
.inner
.advance
(
cnt
);
}
}
impl
<
T
:
Buf
>
io
::
Read
for
Take
<
T
>
{
fn
read
(
&
mut
self
,
buf
:
&
mut
[
u8
])
->
io
::
Result
<
usize
>
{
if
!
self
.has_remaining
()
{
return
Ok
(
0
);
}
Ok
(
self
.read_slice
(
buf
))
}
}
impl
<
T
:
MutBuf
>
MutBuf
for
Take
<
T
>
{
fn
remaining
(
&
self
)
->
usize
{
cmp
::
min
(
self
.inner
.remaining
(),
self
.limit
)
}
fn
mut_bytes
<
'a
>
(
&
'a
mut
self
)
->
&
'a
mut
[
u8
]
{
&
mut
self
.inner
.mut_bytes
()[
..
self
.limit
]
}
fn
advance
(
&
mut
self
,
cnt
:
usize
)
{
let
cnt
=
cmp
::
min
(
cnt
,
self
.limit
);
self
.limit
-=
cnt
;
self
.inner
.advance
(
cnt
);
}
}
This diff is collapsed.
Click to expand it.
src/lib.rs
+
2
−
1
View file @
531c7765
...
...
@@ -17,7 +17,8 @@ pub use buf::{
SliceBuf
,
MutSliceBuf
,
Source
,
Sink
Sink
,
Take
,
};
pub
use
str
::{
ByteStr
,
...
...
This diff is collapsed.
Click to expand it.
test/test.rs
+
1
−
0
View file @
531c7765
...
...
@@ -5,6 +5,7 @@ extern crate rand;
mod
test_buf
;
mod
test_buf_fill
;
mod
test_buf_take
;
mod
test_byte_buf
;
mod
test_bytes
;
mod
test_ring
;
...
...
This diff is collapsed.
Click to expand it.
test/test_buf_take.rs
0 → 100644
+
12
−
0
View file @
531c7765
use
bytes
::
*
;
use
std
::
io
::{
Cursor
,
Read
};
#[test]
pub
fn
test_take_from_buf
()
{
let
mut
buf
=
Take
::
new
(
Cursor
::
new
(
b"hello world"
.to_vec
()),
5
);
let
mut
res
=
vec!
[];
buf
.read_to_end
(
&
mut
res
);
assert_eq!
(
&
res
,
b"hello"
);
}
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