write_int(): remove
This commit is contained in:
parent
8a2bcf13f8
commit
f4245ec937
30
src/fmt.rs
30
src/fmt.rs
|
@ -1,30 +0,0 @@
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
pub struct FmtWrapper<'a> {
|
|
||||||
buf: &'a mut [u8],
|
|
||||||
offset: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> FmtWrapper<'a> {
|
|
||||||
pub fn new(buf: &'a mut [u8]) -> Self {
|
|
||||||
FmtWrapper {
|
|
||||||
buf: buf,
|
|
||||||
offset: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn contents(&self) -> &[u8] {
|
|
||||||
&self.buf[..self.offset]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> fmt::Write for FmtWrapper<'a> {
|
|
||||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
|
||||||
let bytes = s.as_bytes();
|
|
||||||
let remainder = &mut self.buf[self.offset..];
|
|
||||||
let remainder = &mut remainder[..bytes.len()];
|
|
||||||
remainder.copy_from_slice(bytes);
|
|
||||||
self.offset += bytes.len();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -1,6 +1,6 @@
|
||||||
#![no_std]
|
//#![no_std]
|
||||||
|
|
||||||
use core::{fmt::Write, mem::size_of, str};
|
use core::{mem::size_of, str};
|
||||||
use byteorder::{ByteOrder, BigEndian};
|
use byteorder::{ByteOrder, BigEndian};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@ mod error;
|
||||||
pub use error::{Error, ReadError, WriteError};
|
pub use error::{Error, ReadError, WriteError};
|
||||||
mod iter;
|
mod iter;
|
||||||
use iter::Iter;
|
use iter::Iter;
|
||||||
mod fmt;
|
|
||||||
use fmt::FmtWrapper;
|
|
||||||
pub mod no_flash;
|
pub mod no_flash;
|
||||||
mod test;
|
mod test;
|
||||||
|
|
||||||
|
@ -159,14 +157,6 @@ impl<B: StoreBackend> Store<B> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// serialize 32-bit as ASCII, store at `key`
|
|
||||||
pub fn write_int(&mut self, key: &str, value: u32) -> Result<(), Error<B::Error>> {
|
|
||||||
let mut buf = [0; 16];
|
|
||||||
let mut wrapper = FmtWrapper::new(&mut buf);
|
|
||||||
write!(&mut wrapper, "{}", value).unwrap();
|
|
||||||
self.write(key, wrapper.contents())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// encode with `postcard`, write at `key`
|
/// encode with `postcard`, write at `key`
|
||||||
pub fn write_value<T: Serialize>(&mut self, key: &str, value: T) -> Result<(), Error<B::Error>> {
|
pub fn write_value<T: Serialize>(&mut self, key: &str, value: T) -> Result<(), Error<B::Error>> {
|
||||||
let mut buf = [0; 64];
|
let mut buf = [0; 64];
|
||||||
|
|
|
@ -94,13 +94,6 @@ fn write_read_value_f64() {
|
||||||
assert_eq!(store.read_value("foo"), Ok(Some(-1.999e-13f64)));
|
assert_eq!(store.read_value("foo"), Ok(Some(-1.999e-13f64)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn write_int_read_str() {
|
|
||||||
let mut store = make_store();
|
|
||||||
store.write_int("foo", 42).unwrap();
|
|
||||||
assert_eq!(store.read_str("foo").unwrap().unwrap(), "42");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn write_many() {
|
fn write_many() {
|
||||||
let mut store = make_store();
|
let mut store = make_store();
|
||||||
|
|
Loading…
Reference in New Issue