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
b42d94c3
Commit
b42d94c3
authored
8 years ago
by
Carl Lerche
Browse files
Options
Downloads
Patches
Plain Diff
Add BoundBuf
parent
8d2508bf
No related branches found
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/imp/buf/bound.rs
+55
-0
55 additions, 0 deletions
src/imp/buf/bound.rs
src/imp/buf/mod.rs
+1
-0
1 addition, 0 deletions
src/imp/buf/mod.rs
with
56 additions
and
0 deletions
src/imp/buf/bound.rs
0 → 100644
+
55
−
0
View file @
b42d94c3
use
{
Buf
,
IntoBuf
};
use
std
::
mem
;
/// Takes a `T` that can be iterated as a buffer and provides buffer with a
/// 'static lifetime
pub
struct
BoundBuf
<
T
>
where
T
:
'static
,
&
'static
T
:
IntoBuf
{
data
:
T
,
// This should never be mutated
buf
:
<&
'static
T
as
IntoBuf
>
::
Buf
,
// This buf should never leak out
}
impl
<
T
>
BoundBuf
<
T
>
where
&
'static
T
:
IntoBuf
,
{
/// Creates a new `BoundBuf` wrapping the provided data
pub
fn
new
(
data
:
T
)
->
BoundBuf
<
T
>
{
let
buf
=
unsafe
{
let
r
:
&
'static
T
=
mem
::
transmute
(
&
data
);
r
.into_buf
()
};
BoundBuf
{
data
:
data
,
buf
:
buf
,
}
}
/// Consumes this BoundBuf, returning the underlying value.
pub
fn
into_inner
(
self
)
->
T
{
self
.data
}
/// Gets a reference to the underlying value
pub
fn
get_ref
(
&
self
)
->
&
T
{
&
self
.data
}
}
impl
<
T
>
Buf
for
BoundBuf
<
T
>
where
&
'static
T
:
IntoBuf
{
fn
remaining
(
&
self
)
->
usize
{
self
.buf
.remaining
()
}
fn
bytes
(
&
self
)
->
&
[
u8
]
{
self
.buf
.bytes
()
}
fn
advance
(
&
mut
self
,
cnt
:
usize
)
{
self
.buf
.advance
(
cnt
)
}
}
This diff is collapsed.
Click to expand it.
src/imp/buf/mod.rs
+
1
−
0
View file @
b42d94c3
pub
mod
append
;
pub
mod
block
;
pub
mod
bound
;
pub
mod
slice
;
pub
mod
ring
;
pub
mod
take
;
...
...
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