write_int(): remove

This commit is contained in:
Astro 2020-12-11 19:08:12 +01:00
parent 8a2bcf13f8
commit f4245ec937
3 changed files with 2 additions and 49 deletions

View File

@ -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(())
}
}

View File

@ -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 serde::{Deserialize, Serialize};
@ -8,8 +8,6 @@ mod error;
pub use error::{Error, ReadError, WriteError};
mod iter;
use iter::Iter;
mod fmt;
use fmt::FmtWrapper;
pub mod no_flash;
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`
pub fn write_value<T: Serialize>(&mut self, key: &str, value: T) -> Result<(), Error<B::Error>> {
let mut buf = [0; 64];

View File

@ -94,13 +94,6 @@ fn write_read_value_f64() {
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]
fn write_many() {
let mut store = make_store();