mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
xous-ipc: remove most clippy warnings
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
b3cb5ff40a
commit
9b48c0a2ee
1 changed files with 19 additions and 8 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
use xous::{Error, MemoryMessage, Result, CID};
|
use xous::{Error, MemoryMessage, Result, CID};
|
||||||
|
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
use rkyv::ser::Serializer;
|
|
||||||
use rkyv::archived_value;
|
use rkyv::archived_value;
|
||||||
|
use rkyv::ser::Serializer;
|
||||||
use rkyv::ArchiveUnsized;
|
use rkyv::ArchiveUnsized;
|
||||||
use rkyv::SerializeUnsized;
|
use rkyv::SerializeUnsized;
|
||||||
|
|
||||||
|
|
@ -25,16 +25,21 @@ impl<const N: usize> String<N> {
|
||||||
pub fn volatile_clear(&mut self) {
|
pub fn volatile_clear(&mut self) {
|
||||||
let b = self.bytes.as_mut_ptr();
|
let b = self.bytes.as_mut_ptr();
|
||||||
for i in 0..N {
|
for i in 0..N {
|
||||||
unsafe{b.add(i).write_volatile(core::mem::zeroed());}
|
unsafe {
|
||||||
|
b.add(i).write_volatile(core::mem::zeroed());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.len = 0; // also set my length to 0
|
self.len = 0; // also set my length to 0
|
||||||
// Ensure the compiler doesn't re-order the clear.
|
// Ensure the compiler doesn't re-order the clear.
|
||||||
// We use `SeqCst`, because `Acquire` only prevents later accesses from being reordered before
|
// We use `SeqCst`, because `Acquire` only prevents later accesses from being reordered before
|
||||||
// *reads*, but this method only *writes* to the locations.
|
// *reads*, but this method only *writes* to the locations.
|
||||||
core::sync::atomic::compiler_fence(core::sync::atomic::Ordering::SeqCst);
|
core::sync::atomic::compiler_fence(core::sync::atomic::Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_str<T>(src: T) -> String<N> where T: AsRef<str> {
|
pub fn from_str<T>(src: T) -> String<N>
|
||||||
|
where
|
||||||
|
T: AsRef<str>,
|
||||||
|
{
|
||||||
let src = src.as_ref();
|
let src = src.as_ref();
|
||||||
let mut s = Self::new();
|
let mut s = Self::new();
|
||||||
// Copy the string into our backing store.
|
// Copy the string into our backing store.
|
||||||
|
|
@ -130,12 +135,12 @@ impl<const N: usize> String<N> {
|
||||||
/// awful, O(N) implementation because we have to iterate through the entire string
|
/// awful, O(N) implementation because we have to iterate through the entire string
|
||||||
/// and decode variable-length utf8 characters, until we can't.
|
/// and decode variable-length utf8 characters, until we can't.
|
||||||
pub fn pop(&mut self) -> Option<char> {
|
pub fn pop(&mut self) -> Option<char> {
|
||||||
if self.len() < 1 {
|
if self.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
// first, make a copy of the string
|
// first, make a copy of the string
|
||||||
let tempbytes: [u8; N] = self.bytes;
|
let tempbytes: [u8; N] = self.bytes;
|
||||||
let tempstr = unsafe { core::str::from_utf8_unchecked(&tempbytes[0..self.len()]) }.clone();
|
let tempstr = &(*unsafe { core::str::from_utf8_unchecked(&tempbytes[0..self.len()]) });
|
||||||
// clear our own string
|
// clear our own string
|
||||||
self.len = 0;
|
self.len = 0;
|
||||||
self.bytes = [0; N];
|
self.bytes = [0; N];
|
||||||
|
|
@ -214,6 +219,12 @@ impl<const N: usize> String<N> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<const N: usize> Default for String<N> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<const N: usize> core::fmt::Display for String<N> {
|
impl<const N: usize> core::fmt::Display for String<N> {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
write!(f, "{}", self.to_str())
|
write!(f, "{}", self.to_str())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue