Skip to content

Commit

Permalink
Obey clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Licenser committed Feb 7, 2020
1 parent 485cc80 commit d8644d9
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/error.rs
Expand Up @@ -84,6 +84,7 @@ pub enum ErrorType {
}

impl PartialEq for ErrorType {
#[must_use]
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::IO(_), Self::IO(_))
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Expand Up @@ -206,6 +206,9 @@ pub use known_key::{Error as KnownKeyError, KnownKey};
pub use crate::tape::{Node, StaticNode, Tape};

/// Creates a tape from the input for later consumption
/// # Errors
///
/// Will return `Err` if `s` is invalid JSON.
pub fn to_tape<'input>(s: &'input mut [u8]) -> Result<Vec<Node<'input>>> {
let de = stry!(Deserializer::from_slice(s));
Ok(de.tape)
Expand Down
13 changes: 13 additions & 0 deletions src/serde.rs
Expand Up @@ -48,6 +48,10 @@ impl std::error::Error for SerdeConversionError {}

/// parses a byte slice using a serde deserializer.
/// note that the slice will be rewritten in the process.
///
/// # Errors
///
/// Will return `Err` if `s` is invalid JSON.
#[cfg_attr(not(feature = "no-inline"), inline(always))]
pub fn from_slice<'a, T>(s: &'a mut [u8]) -> Result<T>
where
Expand All @@ -59,6 +63,10 @@ where
/// parses a str using a serde deserializer.
/// note that the slice will be rewritten in the process and
/// might not remain a valid utf8 string in its entirety.
///
/// # Errors
///
/// Will return `Err` if `s` is invalid JSON.
#[cfg_attr(not(feature = "no-inline"), inline(always))]
pub fn from_str<'a, T>(s: &'a mut str) -> Result<T>
where
Expand All @@ -70,6 +78,11 @@ where
}

/// parses a Reader using a serde deserializer.
///
/// # Errors
///
/// Will return `Err` if an IO error is encountred while reading
/// rdr or if the readers content is invalid JSON.
#[cfg_attr(not(feature = "no-inline"), inline(always))]
pub fn from_reader<R, T>(mut rdr: R) -> Result<T>
where
Expand Down
5 changes: 5 additions & 0 deletions src/serde/value/borrowed.rs
Expand Up @@ -16,6 +16,11 @@ value.serialize(super::se::Serializer::default())

/// Tries to convert a `BorrowedValue` into a struct that implements
/// serde's Deserialize interface
///
/// # Errors
///
/// Will return `Err` if `value` can not be deserialized

pub fn from_value<'de, T>(value: BorrowedValue<'de>) -> Result<T>
where
T: Deserialize<'de>,
Expand Down
8 changes: 8 additions & 0 deletions src/serde/value/owned.rs
Expand Up @@ -8,6 +8,10 @@ use serde_ext::ser::Serialize;

/// Tries to convert a struct that implements serde's serialize into
/// an `OwnedValue`
///
/// # Errors
///
/// Will return `Err` if value fails to be turned into a owned value
pub fn to_value<T>(value: T) -> Result<OwnedValue>
where
T: Serialize,
Expand All @@ -17,6 +21,10 @@ where

/// Tries to convert a `OwnedValue` into a struct that implements
/// serde's Deserialize interface
///
/// # Errors
///
/// Will return `Err` if `value` fails to be deserialized
pub fn from_value<T>(value: OwnedValue) -> Result<T>
where
T: DeserializeOwned,
Expand Down
16 changes: 16 additions & 0 deletions src/value.rs
Expand Up @@ -165,6 +165,9 @@ pub trait MutableValue: IndexMut<usize> + Value + Sized {
/// Will return an `AccessError::NotAnObject` if called
/// on a `Value` that isn't an object - otherwise will
/// behave the same as `HashMap::insert`
/// # Errors
///
/// Will return `Err` if `self` is not an object.
#[inline]
fn insert<K, V>(&mut self, k: K, v: V) -> std::result::Result<Option<Self>, AccessError>
where
Expand All @@ -181,6 +184,9 @@ pub trait MutableValue: IndexMut<usize> + Value + Sized {
/// Will return an `AccessError::NotAnObject` if called
/// on a `Value` that isn't an object - otherwise will
/// behave the same as `HashMap::remove`
/// # Errors
///
/// Will return `Err` if `self` is not an Object.
#[inline]
fn remove<Q: ?Sized>(&mut self, k: &Q) -> std::result::Result<Option<Self>, AccessError>
where
Expand All @@ -196,6 +202,9 @@ pub trait MutableValue: IndexMut<usize> + Value + Sized {
/// Will return an `AccessError::NotAnArray` if called
/// on a `Value` that isn't an `Array` - otherwise will
/// behave the same as `Vec::push`
/// # Errors
///
/// Will return `Err` if `self` is not an array.
#[inline]
fn push<V>(&mut self, v: V) -> std::result::Result<(), AccessError>
where
Expand All @@ -210,6 +219,9 @@ pub trait MutableValue: IndexMut<usize> + Value + Sized {
/// Will return an `AccessError::NotAnArray` if called
/// on a `Value` that isn't an `Array` - otherwise will
/// behave the same as `Vec::pop`
/// # Errors
///
/// Will return `Err` if `self` is not an array.
#[inline]
fn pop(&mut self) -> std::result::Result<Option<Self>, AccessError> {
self.as_array_mut()
Expand Down Expand Up @@ -516,6 +528,10 @@ pub trait Value:
/// rewrite the slice to de-escape strings.
/// As we reference parts of the input slice the resulting dom
/// has the dame lifetime as the slice it was created from.
///
/// # Errors
///
/// Will return `Err` if `s` is invalid JSON.
pub fn deserialize<'de, Value, Key>(s: &'de mut [u8]) -> Result<Value>
where
Value: ValueBuilder + From<&'de str> + From<Vec<Value>> + From<HashMap<Key, Value>> + 'de,
Expand Down
4 changes: 4 additions & 0 deletions src/value/borrowed.rs
Expand Up @@ -38,6 +38,10 @@ pub type Object<'v> = HashMap<Cow<'v, str>, Value<'v>>;
/// rewrite the slice to de-escape strings.
/// As we reference parts of the input slice the resulting dom
/// has the dame lifetime as the slice it was created from.
///
/// # Errors
///
/// Will return `Err` if `s` is invalid JSON.
pub fn to_value<'v>(s: &'v mut [u8]) -> Result<Value<'v>> {
match Deserializer::from_slice(s) {
Ok(de) => Ok(BorrowDeserializer::from_deserializer(de).parse()),
Expand Down
8 changes: 8 additions & 0 deletions src/value/borrowed/serialize.rs
Expand Up @@ -34,6 +34,10 @@ impl<'value> Value<'value> {
}

/// Encodes the value into it's JSON representation into a Writer
///
/// # Errors
///
/// Will return `Err` if an IO error is encountered
pub fn write<'writer, W>(&self, w: &mut W) -> io::Result<()>
where
W: 'writer + Write,
Expand All @@ -43,6 +47,10 @@ impl<'value> Value<'value> {
}

/// Encodes the value into it's JSON representation into a Writer, pretty printed
///
/// # Errors
///
/// Will return `Err` if an IO error is encountered
pub fn write_pp<'writer, W>(&self, w: &mut W) -> io::Result<()>
where
W: 'writer + Write,
Expand Down
4 changes: 4 additions & 0 deletions src/value/owned.rs
Expand Up @@ -37,6 +37,10 @@ pub type Object = HashMap<String, Value>;
/// We do not keep any references to the raw data but re-allocate
/// owned memory whereever required thus returning a value without
/// a lifetime.
///
/// # Errors
///
/// Will return `Err` if `s` is invalid JSON.
pub fn to_value(s: &mut [u8]) -> Result<Value> {
match Deserializer::from_slice(s) {
Ok(de) => Ok(OwnedDeserializer::from_deserializer(de).parse()),
Expand Down
8 changes: 8 additions & 0 deletions src/value/owned/serialize.rs
Expand Up @@ -33,6 +33,10 @@ impl Value {
}

/// Encodes the value into it's JSON representation into a Writer
///
/// # Errors
///
/// Will return `Err` if an IO error is encountered
#[inline]
pub fn write<'writer, W>(&self, w: &mut W) -> io::Result<()>
where
Expand All @@ -43,6 +47,10 @@ impl Value {
}

/// Encodes the value into it's JSON representation into a Writer, pretty printed
///
/// # Errors
///
/// Will return `Err` if an IO error is encountered.
#[inline]
pub fn write_pp<'writer, W>(&self, w: &mut W) -> io::Result<()>
where
Expand Down

0 comments on commit d8644d9

Please sign in to comment.