Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraef committed Jul 13, 2024
1 parent e295209 commit c7bf566
Show file tree
Hide file tree
Showing 24 changed files with 99 additions and 83 deletions.
8 changes: 4 additions & 4 deletions byst/src/buf/arc_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl BufferRef {
/// portion of the buffer. Furthermore the caller must not write
/// uninitialized values into the initialized portion of the buffer.
#[inline]
unsafe fn uninitialized_mut(&self) -> &mut [MaybeUninit<u8>] {
unsafe fn uninitialized_mut(&mut self) -> &mut [MaybeUninit<u8>] {
// SAFETY:
// - `Buffer` is valid, since we have a `BufferRef` to it.
// - The range is valid
Expand Down Expand Up @@ -392,7 +392,7 @@ impl BufferRef {
/// valid. No other active references, mutable or not may exist to this
/// portion of the buffer.
#[inline]
unsafe fn initialized_mut(&self) -> &mut [u8] {
unsafe fn initialized_mut(&mut self) -> &mut [u8] {
let initialized = self.initialized_end();

// SAFETY:
Expand Down Expand Up @@ -929,7 +929,7 @@ impl ArcBufMut {

/// Returns a mutable reference to the filled portion of the buffer.
#[inline]
fn filled_mut(&self) -> &mut [u8] {
fn filled_mut(&mut self) -> &mut [u8] {
unsafe {
// SAFETY:
//
Expand Down Expand Up @@ -993,7 +993,7 @@ impl ArcBufMut {
/// [`set_filled_to`]: Self::set_filled_to
/// [`fully_initialize`]: Self::fully_initialize
#[inline]
pub fn initialized_mut(&self) -> &mut [u8] {
pub fn initialized_mut(&mut self) -> &mut [u8] {
unsafe {
// SAFETY:
//
Expand Down
2 changes: 0 additions & 2 deletions byst/src/buf/array_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ impl<const N: usize> Clone for ArrayBuf<N> {
}
}

impl<const N: usize> Copy for ArrayBuf<N> {}

impl<const N: usize> Debug for ArrayBuf<N> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Debug::fmt(&self.inner, f)
Expand Down
9 changes: 6 additions & 3 deletions byst/src/buf/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ pub struct WithOffset<I> {
impl<I> WithOffset<I> {
#[inline]
pub fn new(inner: I) -> Self {
Self::with_offset(inner, 0)
Self::with_initial_offset(inner, 0)
}

#[inline]
pub fn with_offset(inner: I, offset: usize) -> Self {
Self { inner, offset }
pub fn with_initial_offset(inner: I, initial_offset: usize) -> Self {
Self {
inner,
offset: initial_offset,
}
}

#[inline]
Expand Down
11 changes: 5 additions & 6 deletions byst/src/buf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ pub trait BufExt: Buf {
BufIter::new(self)
}

#[inline]
fn into_vec(&self) -> Vec<u8> {
fn as_vec(&self) -> Vec<u8> {
let mut reader = self.reader();
let mut buf = Vec::with_capacity(reader.remaining());
while let Some(chunk) = reader.peek_chunk() {
Expand Down Expand Up @@ -182,21 +181,21 @@ impl<'a, T: Length + ?Sized> Length for &'a mut T {
}
}

impl<'a, T: Length + ?Sized> Length for Box<T> {
impl<T: Length + ?Sized> Length for Box<T> {
#[inline]
fn len(&self) -> usize {
T::len(self)
}
}

impl<'a, T: Length + ?Sized> Length for Arc<T> {
impl<T: Length + ?Sized> Length for Arc<T> {
#[inline]
fn len(&self) -> usize {
T::len(self)
}
}

impl<'a, T: Length + ?Sized> Length for Rc<T> {
impl<T: Length + ?Sized> Length for Rc<T> {
#[inline]
fn len(&self) -> usize {
T::len(self)
Expand All @@ -210,7 +209,7 @@ impl<'a, T: Length + ToOwned + ?Sized> Length for Cow<'a, T> {
}
}

impl<'a> Length for Vec<u8> {
impl Length for Vec<u8> {
#[inline]
fn len(&self) -> usize {
Vec::len(self)
Expand Down
12 changes: 6 additions & 6 deletions byst/src/buf/rope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ mod tests {
.collect::<Rope<_>>();

let view = rope.view(2..9).unwrap();
assert_eq!(view.into_vec(), b"llo Wor");
assert_eq!(view.as_vec(), b"llo Wor");

let view = rope.view(5..9).unwrap();
assert_eq!(view.into_vec(), b" Wor");
assert_eq!(view.as_vec(), b" Wor");

let view = rope.view(6..).unwrap();
assert_eq!(view.into_vec(), b"World!");
assert_eq!(view.as_vec(), b"World!");
}

#[test]
Expand Down Expand Up @@ -408,15 +408,15 @@ mod tests {

let view = rope.view(2..9).unwrap();
let view2 = view.view(2..4).unwrap();
assert_eq!(view2.into_vec(), b"o ");
assert_eq!(view2.as_vec(), b"o ");

let view = rope.view(5..9).unwrap();
let view2 = view.view(1..).unwrap();
assert_eq!(view2.into_vec(), b"Wor");
assert_eq!(view2.as_vec(), b"Wor");

let view = rope.view(6..).unwrap();
let view2 = view.view(..5).unwrap();
assert_eq!(view2.into_vec(), b"World");
assert_eq!(view2.as_vec(), b"World");
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions byst/src/buf/slab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ mod tests {
copy(&mut bytes_mut, b"abcd").unwrap();

let bytes = bytes_mut.freeze();
assert_eq!(bytes.into_vec(), b"abcd");
assert_eq!(bytes.as_vec(), b"abcd");

let bytes2 = bytes.clone();
assert_eq!(bytes2.into_vec(), b"abcd");
assert_eq!(bytes2.as_vec(), b"abcd");
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions byst/src/bytes/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ impl Default for Bytes {
}
}

impl<'b> Debug for Bytes {
impl Debug for Bytes {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
debug_as_hexdump(f, self)
}
}

impl<'b, R: Buf> PartialEq<R> for Bytes {
impl<R: Buf> PartialEq<R> for Bytes {
#[inline]
fn eq(&self, other: &R) -> bool {
buf_eq(self, other)
Expand Down
4 changes: 2 additions & 2 deletions byst/src/bytes/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ impl Default for BytesMut {
}
}

impl<'b> Debug for BytesMut {
impl Debug for BytesMut {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
debug_as_hexdump(f, self)
}
}

impl<'b, R: Buf> PartialEq<R> for BytesMut {
impl<R: Buf> PartialEq<R> for BytesMut {
#[inline]
fn eq(&self, other: &R) -> bool {
buf_eq(self, other)
Expand Down
1 change: 1 addition & 0 deletions byst/src/bytes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(clippy::module_inception)]
pub mod bytes;
pub mod bytes_mut;
//mod spilled;
Expand Down
16 changes: 8 additions & 8 deletions byst/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ impl Range {
(Some(left), Some(right)) if left > right => return false,
_ => {}
}
match (self.end, other.end) {
(Some(left), Some(right)) if left < right => false,
_ => true,
}
!matches!(
(self.end, other.end),
(Some(left), Some(right)) if left < right
)
}

#[inline]
Expand All @@ -216,10 +216,10 @@ impl Range {
Some(start) if start > index => return false,
_ => {}
}
match self.end {
Some(end) if end < index => false,
_ => true,
}
!matches!(
self.end,
Some(end) if end < index
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion skunk-api-client/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl<'a> ReactorConnection<'a> {
// todo: Our implementation only supports one subscription at a time right now.

if let Some(flows_tx) = self.reactor.flows_tx.get_mut(&subscription_id) {
if let Err(_) = flows_tx.send(event).await {
if flows_tx.send(event).await.is_err() {
// the flows receiver has been dropped.
self.reactor.flows_tx.remove(&subscription_id);
}
Expand Down
6 changes: 3 additions & 3 deletions skunk-cli/src/env/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Inner {
let deserializer = value.into_deserializer();
let value = T::deserialize(deserializer).map_err(|error| {
Error::ParseToml {
error: error.into(),
error: Box::new(error.into()),
path: self.path.clone(),
toml: item.to_string(),
}
Expand Down Expand Up @@ -157,7 +157,7 @@ fn open(path: &Path) -> Result<Loader, Error> {

let document: DocumentMut = toml.parse().map_err(|error| {
Error::ParseToml {
error,
error: Box::new(error),
path: path.to_owned(),
toml: toml.clone().into_owned(),
}
Expand Down Expand Up @@ -206,7 +206,7 @@ impl WatchConfig {
if hash != self.hash {
let document: DocumentMut = toml.parse().map_err(|error| {
Error::ParseToml {
error,
error: Box::new(error),
path: self.path.to_owned(),
toml,
}
Expand Down
2 changes: 1 addition & 1 deletion skunk-cli/src/env/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum Error {
#[error("Could not parse TOML file: {path}")]
ParseToml {
#[source]
error: toml_edit::TomlError,
error: Box<toml_edit::TomlError>,
path: PathBuf,
toml: String,
},
Expand Down
2 changes: 1 addition & 1 deletion skunk-cli/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub async fn run(environment: Environment, args: ProxyArgs) -> Result<(), Error>
}
}

while let Some(_) = join_set.join_next().await {}
while join_set.join_next().await.is_some() {}

Ok::<(), Error>(())
});
Expand Down
4 changes: 2 additions & 2 deletions skunk-macros/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ fn parse_mac_address(mut s: &str) -> Option<[u8; 6]> {
let mut buf = [0u8; 6];

buf[0] = hex(&mut s)?;
for i in 1..6 {
for b in &mut buf[1..6] {
colon(&mut s)?;
buf[i] = hex(&mut s)?;
*b = hex(&mut s)?;
}

Some(buf)
Expand Down
Loading

0 comments on commit c7bf566

Please sign in to comment.