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
4ebffd01
Commit
4ebffd01
authored
10 years ago
by
Carl Lerche
Browse files
Options
Downloads
Patches
Plain Diff
Add more documentation
parent
66c00aaf
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/bytes.rs
+1
-86
1 addition, 86 deletions
src/bytes.rs
src/lib.rs
+11
-6
11 additions, 6 deletions
src/lib.rs
with
12 additions
and
92 deletions
src/bytes.rs
+
1
−
86
View file @
4ebffd01
...
...
@@ -6,6 +6,7 @@ use core::nonzero::NonZero;
const
INLINE
:
usize
=
1
;
/// A specialized `ByteStr` box.
#[unsafe_no_drop_flag]
pub
struct
Bytes
{
vtable
:
NonZero
<
usize
>
,
...
...
@@ -252,92 +253,6 @@ impl<B: ByteStr + 'static> ByteStrPriv for B {
}
}
/*
impl ops::Index<usize> for Bytes {
type Output = u8;
fn index(&self, index: &usize) -> &u8 {
self.bytes.index(index)
}
}
impl PartialEq<Bytes> for Bytes {
fn eq(&self, other: &Bytes) -> bool {
let mut i1 = self.iter();
let mut i2 = other.iter();
loop {
let el = i1.next();
if el != i2.next() {
return false;
}
if el.is_none() {
return true;
}
}
}
}
pub struct BytesIter<'a> {
bytes: &'a Bytes,
pos: usize,
}
impl<'a> Iterator for BytesIter<'a> {
type Item = u8;
fn next(&mut self) -> Option<u8> {
if self.pos == self.bytes.len() {
return None;
}
let ret = self.bytes[self.pos];
self.pos += 1;
Some(ret)
}
}
#[cfg(test)]
mod test {
use super::Bytes;
#[test]
pub fn test_accessing_bytes() {
let bytes = from_slice(b"foo");
for i in 0..3us {
assert_eq!(b"foo"[i], bytes[i]);
}
}
/*
*
* ===== Equality =====
*
*/
#[test]
pub fn test_literal_bytes_eq() {
assert!(from_slice(b"foo") == from_slice(b"foo"));
assert!(from_slice(b"foo") != from_slice(b"bar"));
assert!(from_slice(b"foo") != from_slice(b"foo*"));
assert!(from_slice(b"foo*") != from_slice(b"foo"));
}
/*
*
* ===== Helpers =====
*
*/
fn from_slice(bytes: &[u8]) -> Bytes {
Bytes::from_slice(bytes)
}
}
*/
#[test]
pub
fn
test_size_of
()
{
let
expect
=
mem
::
size_of
::
<
usize
>
()
*
2
;
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
11
−
6
View file @
4ebffd01
...
...
@@ -24,12 +24,13 @@ mod rope;
mod
slice
;
pub
mod
traits
{
//! All traits are re-exported here to allow glob imports.
pub
use
{
Buf
,
BufExt
,
MutBuf
,
MutBufExt
,
ByteStr
};
}
const
MAX_CAPACITY
:
usize
=
u32
::
MAX
as
usize
;
/// A trait for values that provide
random and
sequential access to bytes.
/// A trait for values that provide sequential
read
access to bytes.
pub
trait
Buf
{
/// Returns the number of bytes that can be accessed from the Buf
...
...
@@ -99,6 +100,7 @@ pub trait Buf {
}
}
/// An extension trait providing extra functions applicable to all `Buf` values.
pub
trait
BufExt
{
/// Read bytes from this Buf into the given sink and advance the cursor by
...
...
@@ -106,7 +108,7 @@ pub trait BufExt {
fn
read
<
S
:
Sink
>
(
&
mut
self
,
dst
:
S
)
->
Result
<
usize
,
S
::
Error
>
;
}
//
TODO: Remove Sized
//
/ A trait for values that provide sequential write access to bytes.
pub
trait
MutBuf
:
Sized
{
/// Returns the number of bytes that can be accessed from the Buf
...
...
@@ -180,6 +182,7 @@ pub trait MutBuf : Sized {
}
}
/// An extension trait providing extra functions applicable to all `MutBuf` values.
pub
trait
MutBufExt
{
/// Write bytes from the given source into the current `MutBuf` and advance
...
...
@@ -193,6 +196,9 @@ pub trait MutBufExt {
*
*/
/// An immutable sequence of bytes. Operations will not mutate the original
/// value. Since only immutable access is permitted, operations do not require
/// copying (though, sometimes copying will happen as an optimization).
pub
trait
ByteStr
:
Clone
+
Sized
+
Send
+
Sync
+
ops
::
Index
<
usize
,
Output
=
u8
>
{
// Until HKT lands, the buf must be bound by 'static
...
...
@@ -274,13 +280,14 @@ impl<B: MutBuf> MutBufExt for B {
*
*/
/// A
n
value that reads bytes from a Buf into itself
/// A value that reads bytes from a Buf into itself
pub
trait
Sink
{
type
Error
;
fn
sink
<
B
:
Buf
>
(
self
,
buf
:
&
mut
B
)
->
Result
<
usize
,
Self
::
Error
>
;
}
/// A value that writes bytes from itself into a `MutBuf`.
pub
trait
Source
{
type
Error
;
...
...
@@ -389,7 +396,7 @@ impl Buf for Box<Buf+'static> {
/*
*
* ===== BufError
/ BufResult
=====
* ===== BufError =====
*
*/
...
...
@@ -398,5 +405,3 @@ pub enum BufError {
Underflow
,
Overflow
,
}
pub
type
BufResult
<
T
>
=
Result
<
T
,
BufError
>
;
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