Skip to content

Commit

Permalink
inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
mcatanzariti committed Jan 2, 2023
1 parent d371c20 commit 1fd7a13
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/resp/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ impl Value {
///
/// # Errors
/// Any parsing error ([`Error::Client`](crate::Error::Client)) due to incompatibility between Value variant and taget type
#[inline]
pub fn into<T>(self) -> Result<T>
where
T: FromValue,
{
T::from_value(self)
}

#[inline]
pub fn into_with_command<T>(self, command: &Command) -> Result<T>
where
T: FromValue,
Expand All @@ -57,6 +59,7 @@ impl Value {
}

impl Default for Value {
#[inline]
fn default() -> Self {
Value::Nil
}
Expand Down Expand Up @@ -221,6 +224,7 @@ pub(crate) trait IntoValueIterator<I: Iterator<Item = Value>>: Sized {
}

impl IntoValueIterator<std::vec::IntoIter<Value>> for Vec<Value> {
#[inline]
fn into_value_iter<T>(self) -> ValueIterator<T, std::vec::IntoIter<Value>>
where
T: FromValue,
Expand All @@ -245,6 +249,7 @@ where
T: FromValue,
I: Iterator<Item = Value>,
{
#[inline]
pub fn new(iter: I) -> Self {
Self {
iter,
Expand All @@ -261,6 +266,7 @@ where
{
type Item = Result<T>;

#[inline]
fn next(&mut self) -> Option<Self::Item> {
(self.next_functor)(&mut self.iter)
}
Expand Down
6 changes: 3 additions & 3 deletions src/resp/value_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn decode(buf: &mut BytesMut, idx: usize) -> Result<Option<(Value, usize)>> {
b'-' => decode_string(buf, idx)?
.map(|(s, pos)| RedisError::from_str(s).map(|e| (Value::Error(e), pos)))
.transpose(),
b'_' => Ok(decode_null(buf, idx)?.map(|pos| (Value::Nil, pos))),
b'_' => Ok(decode_nil(buf, idx)?.map(|pos| (Value::Nil, pos))),
b'#' => Ok(decode_boolean(buf, idx)?.map(|(b, pos)| (Value::Boolean(b), pos))),
b'=' => Ok(decode_bulk_string(buf, idx)?.map(|(bs, pos)| (Value::BulkString(bs), pos))),
b'>' => Ok(decode_array(buf, idx)?.map(|(v, pos)| (Value::Push(v), pos))),
Expand Down Expand Up @@ -162,11 +162,11 @@ where
}
}

fn decode_null(buf: &mut BytesMut, idx: usize) -> Result<Option<usize>> {
fn decode_nil(buf: &mut BytesMut, idx: usize) -> Result<Option<usize>> {
match decode_line(buf, idx)? {
Some((slice, pos)) if slice.is_empty() => Ok(Some(pos)),
None => Ok(None),
_ => Err(Error::Client("Cannot parse null".to_owned())),
_ => Err(Error::Client("Cannot parse nil".to_owned())),
}
}

Expand Down

0 comments on commit 1fd7a13

Please sign in to comment.