Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rust-card10
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Astro
rust-card10
Commits
ad10b054
Commit
ad10b054
authored
5 years ago
by
Astro
Browse files
Options
Downloads
Patches
Plain Diff
rm unused fmt_buffer
parent
8d5251a2
No related branches found
No related tags found
1 merge request
!22
Remove str_to_cstr
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
card10-l0dable/src/fmt_buffer.rs
+0
-56
0 additions, 56 deletions
card10-l0dable/src/fmt_buffer.rs
card10-l0dable/src/lib.rs
+0
-2
0 additions, 2 deletions
card10-l0dable/src/lib.rs
with
0 additions
and
58 deletions
card10-l0dable/src/fmt_buffer.rs
deleted
100644 → 0
+
0
−
56
View file @
8d5251a2
//! Stolen from https://stackoverflow.com/questions/39488327/how-to-format-output-to-a-byte-array-with-no-std-and-no-allocator
use
core
::
fmt
::{
self
,
Write
};
use
core
::
mem
::
uninitialized
;
use
core
::
str
::
from_utf8_unchecked
;
pub
struct
FmtBuffer
<
'a
>
{
buf
:
&
'a
mut
[
u8
],
offset
:
usize
,
}
impl
<
'a
>
FmtBuffer
<
'a
>
{
pub
fn
new
(
buf
:
&
'a
mut
[
u8
])
->
Self
{
FmtBuffer
{
buf
:
buf
,
offset
:
0
,
}
}
}
impl
<
'a
>
fmt
::
Write
for
FmtBuffer
<
'a
>
{
fn
write_str
(
&
mut
self
,
s
:
&
str
)
->
fmt
::
Result
{
let
bytes
=
s
.as_bytes
();
// Skip over already-copied data
let
remainder
=
&
mut
self
.buf
[
self
.offset
..
];
// Check if there is space remaining (return error instead of panicking)
if
remainder
.len
()
<
bytes
.len
()
{
return
Err
(
core
::
fmt
::
Error
);
}
// Make the two slices the same length
let
remainder
=
&
mut
remainder
[
..
bytes
.len
()];
// Copy
remainder
.copy_from_slice
(
bytes
);
// Update offset to avoid overwriting
self
.offset
+=
bytes
.len
();
Ok
(())
}
}
/// 255 bytes ought to be enough for any C string
pub
fn
str_to_cstr
(
s
:
&
str
)
->
[
u8
;
256
]
{
let
mut
buf
:
[
u8
;
256
]
=
unsafe
{
uninitialized
()
};
let
mut
fmt
=
FmtBuffer
::
new
(
buf
.as_mut
());
write!
(
fmt
,
"{}
\0
"
,
s
)
.unwrap
();
buf
}
impl
AsRef
<
str
>
for
FmtBuffer
<
'_
>
{
fn
as_ref
(
&
self
)
->
&
str
{
let
len
=
self
.buf
.iter
()
.position
(|
b
|
*
b
==
0
)
.unwrap_or
(
0
);
unsafe
{
from_utf8_unchecked
(
&
self
.buf
[
0
..
len
])
}
}
}
This diff is collapsed.
Click to expand it.
card10-l0dable/src/lib.rs
+
0
−
2
View file @
ad10b054
...
@@ -16,8 +16,6 @@ mod rtc;
...
@@ -16,8 +16,6 @@ mod rtc;
pub
mod
trng
;
pub
mod
trng
;
pub
mod
vibra
;
pub
mod
vibra
;
pub
use
rtc
::{
MilliSeconds
,
Seconds
,
Time
};
pub
use
rtc
::{
MilliSeconds
,
Seconds
,
Time
};
mod
fmt_buffer
;
pub
use
fmt_buffer
::{
str_to_cstr
,
FmtBuffer
};
mod
bme680
;
mod
bme680
;
pub
use
bme680
::
BME680
;
pub
use
bme680
::
BME680
;
mod
bhi160
;
mod
bhi160
;
...
...
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