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
a76dd8ed
Commit
a76dd8ed
authored
9 years ago
by
Nandor Kracser
Committed by
Carl Lerche
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add clear method to RingBuf
parent
4ce8b1c2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/buf/ring.rs
+7
-0
7 additions, 0 deletions
src/buf/ring.rs
test/test_ring.rs
+16
-0
16 additions, 0 deletions
test/test_ring.rs
with
23 additions
and
0 deletions
src/buf/ring.rs
+
7
−
0
View file @
a76dd8ed
...
...
@@ -91,6 +91,13 @@ impl RingBuf {
}
}
/// Resets all internal state to the initial state.
pub
fn
clear
(
&
mut
self
)
{
self
.pos
=
0
;
self
.len
=
0
;
self
.mark
=
Mark
::
NoMark
;
}
/// Returns the number of bytes remaining to read.
fn
read_remaining
(
&
self
)
->
usize
{
self
.len
...
...
This diff is collapsed.
Click to expand it.
test/test_ring.rs
+
16
−
0
View file @
a76dd8ed
...
...
@@ -120,3 +120,19 @@ fn test_reset_full() {
buf
.reset
();
assert_eq!
(
MutBuf
::
remaining
(
&
buf
),
0
);
}
#[test]
// Test that "RingBuf::clear" does the full reset
fn
test_clear
()
{
use
bytes
::
traits
::{
Buf
,
MutBuf
};
use
std
::
io
::
Write
;
let
mut
buf
=
RingBuf
::
new
(
8
);
buf
.write
(
&
[
0
;
8
])
.unwrap
();
assert_eq!
(
MutBuf
::
remaining
(
&
buf
),
0
);
assert_eq!
(
Buf
::
remaining
(
&
buf
),
8
);
buf
.clear
();
assert_eq!
(
MutBuf
::
remaining
(
&
buf
),
8
);
assert_eq!
(
Buf
::
remaining
(
&
buf
),
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