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
4ca7e0fa
Commit
4ca7e0fa
authored
8 years ago
by
Carl Lerche
Browse files
Options
Downloads
Patches
Plain Diff
Add IntoBuf trait
parent
b10992a5
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
examples/into_buf.rs
+17
-0
17 additions, 0 deletions
examples/into_buf.rs
src/imp/buf/mod.rs
+34
-0
34 additions, 0 deletions
src/imp/buf/mod.rs
src/imp/bytes/mod.rs
+15
-1
15 additions, 1 deletion
src/imp/bytes/mod.rs
src/lib.rs
+1
-1
1 addition, 1 deletion
src/lib.rs
with
67 additions
and
2 deletions
examples/into_buf.rs
0 → 100644
+
17
−
0
View file @
4ca7e0fa
extern
crate
bytes
;
use
bytes
::{
Buf
,
IntoBuf
,
Bytes
};
pub
fn
dump
<
T
>
(
data
:
&
T
)
where
for
<
'a
>
&
'a
T
:
IntoBuf
,
{
let
mut
dst
:
Vec
<
u8
>
=
vec!
[];
data
.into_buf
()
.copy_to
(
&
mut
dst
);
println!
(
"GOT: {:?}"
,
dst
);
}
pub
fn
main
()
{
let
b
=
Bytes
::
from_slice
(
b"hello world"
);
dump
(
&
b
);
dump
(
&
b
);
}
This diff is collapsed.
Click to expand it.
src/imp/buf/mod.rs
+
34
−
0
View file @
4ca7e0fa
...
...
@@ -363,6 +363,40 @@ pub trait MutBuf {
}
}
/*
*
* ===== IntoBuf =====
*
*/
/// Conversion into a `Buf`
///
/// Usually, `IntoBuf` is implemented on references of types and not directly
/// on the types themselves. For example, `IntoBuf` is implemented for `&'a
/// Vec<u8>` and not `Vec<u8>` directly.
pub
trait
IntoBuf
{
type
Buf
:
Buf
;
fn
into_buf
(
self
)
->
Self
::
Buf
;
}
impl
<
'a
>
IntoBuf
for
&
'a
[
u8
]
{
type
Buf
=
io
::
Cursor
<&
'a
[
u8
]
>
;
/// Creates a buffer from a value
fn
into_buf
(
self
)
->
Self
::
Buf
{
io
::
Cursor
::
new
(
self
)
}
}
impl
<
'a
>
IntoBuf
for
&
'a
Vec
<
u8
>
{
type
Buf
=
io
::
Cursor
<&
'a
[
u8
]
>
;
fn
into_buf
(
self
)
->
Self
::
Buf
{
io
::
Cursor
::
new
(
&
self
[
..
])
}
}
/*
*
* ===== Sink / Source =====
...
...
This diff is collapsed.
Click to expand it.
src/imp/bytes/mod.rs
+
15
−
1
View file @
4ca7e0fa
...
...
@@ -2,7 +2,7 @@ pub mod rope;
pub
mod
seq
;
pub
mod
small
;
use
Buf
;
use
{
Buf
,
IntoBuf
}
;
use
self
::
seq
::
Seq
;
use
self
::
small
::
Small
;
use
self
::
rope
::{
Rope
,
RopeBuf
};
...
...
@@ -188,6 +188,20 @@ impl cmp::PartialEq<Bytes> for Bytes {
}
}
impl
<
'a
>
IntoBuf
for
&
'a
Bytes
{
type
Buf
=
BytesBuf
<
'a
>
;
fn
into_buf
(
self
)
->
Self
::
Buf
{
self
.buf
()
}
}
/*
*
* ===== BytesBuf =====
*
*/
impl
<
'a
>
Buf
for
BytesBuf
<
'a
>
{
fn
remaining
(
&
self
)
->
usize
{
match
self
.kind
{
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
1
−
1
View file @
4ca7e0fa
...
...
@@ -10,7 +10,7 @@ mod imp;
// TODO: delete
mod
alloc
;
pub
use
imp
::
buf
::{
Buf
,
MutBuf
};
pub
use
imp
::
buf
::{
Buf
,
MutBuf
,
IntoBuf
};
pub
use
imp
::
bytes
::
Bytes
;
pub
mod
buf
{
...
...
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