Skip to content

Commit 006a50b

Browse files
committed
Fixed PartialEq for Short, more comments.
1 parent 5560f25 commit 006a50b

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ assert!(data["this"]["does"]["not"]["exist"].is_null());
8888
data["list"][0] = "Hello".into();
8989

9090
// Use the `dump` method to serialize the data:
91-
assert_eq!(data.dump(), r#"{"answer":42,"bar":null,"foo":false,"list":["Hello","world",true]}"#);
91+
assert_eq!(data.dump(), r#"{"foo":false,"bar":null,"answer":42,"list":["Hello","world",true]}"#);
9292

9393
// Or pretty print it out:
9494
println!("{:#}", data);

src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use std::{ char, error, fmt };
22

33
#[derive(Debug, PartialEq)]
4+
/// Error type of this crate.
5+
///
6+
///
7+
/// *Note:* Since `0.9.0` using `JsonError` is deprecated. Always use
8+
/// `json::Error` instead!
49
pub enum Error {
510
UnexpectedCharacter {
611
ch: char,

src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ use object::Object;
213213
pub use error::Error;
214214
pub use value::JsonValue;
215215
pub use value::JsonValue::Null;
216+
217+
/// Result type used by this crate.
218+
///
219+
///
220+
/// *Note:* Since 0.9.0 the old `JsonResult` type is depreacted. Always use
221+
/// `json::Result` instead.
216222
pub type Result<T> = result::Result<T, Error>;
217223

218224
/// Iterator over members of `JsonValue::Array`.
@@ -222,11 +228,9 @@ pub type Members<'a> = slice::Iter<'a, JsonValue>;
222228
pub type MembersMut<'a> = slice::IterMut<'a, JsonValue>;
223229

224230
/// Iterator over key value pairs of `JsonValue::Object`.
225-
// pub type Entries<'a> = btree_map::Iter<'a, String, JsonValue>;
226231
pub type Entries<'a> = object::Iter<'a>;
227232

228233
/// Mutable iterator over key value pairs of `JsonValue::Object`.
229-
// pub type EntriesMut<'a> = btree_map::IterMut<'a, String, JsonValue>;
230234
pub type EntriesMut<'a> = object::IterMut<'a>;
231235

232236
#[deprecated(since="0.9.0", note="use `json::Error` instead")]

src/object.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl Clone for Node {
221221
}
222222
}
223223

224-
/// A binary tree implementation of string -> `JsonValue` map. You normally don't
224+
/// A binary tree implementation of a string -> `JsonValue` map. You normally don't
225225
/// have to interact with instances of `Object`, much more likely you will be
226226
/// using the `JsonValue::Object` variant, which wraps around this struct.
227227
#[derive(Debug)]
@@ -231,14 +231,14 @@ pub struct Object {
231231

232232
impl Object {
233233
/// Create a new, empty instance of `Object`. Empty `Object` performs no
234-
/// allocation until a value is pushed onto it.
234+
/// allocation until a value is inserted into it.
235235
pub fn new() -> Self {
236236
Object {
237237
store: Vec::new()
238238
}
239239
}
240240

241-
/// Create a new object with memory preallocated with `capacity` for a number
241+
/// Create a new `Object` with memory preallocated for `capacity` number
242242
/// of entries.
243243
pub fn with_capacity(capacity: usize) -> Self {
244244
Object {

src/short.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ops::Deref;
33

44
pub const MAX_LEN: usize = 30;
55

6-
#[derive(Clone, Copy, PartialEq)]
6+
#[derive(Clone, Copy)]
77
pub struct Short {
88
value: [u8; MAX_LEN],
99
len: u8,
@@ -13,10 +13,13 @@ pub struct Short {
1313
/// the expensive heap allocation performed for the regular `String` type.
1414
impl Short {
1515
/// Creates a `Short` from a `&str` slice. This method can cause buffer
16-
/// overflow if the length of the slice is larger than `MAX_LEN`. Typically
17-
/// you should never want to create your own `Short`s, instead creating a
18-
/// `JsonValue` (using `.into()` or `JsonValue::from(slice)`) out of a slice
19-
/// will automatically decide on `String` or `Short` for you.
16+
/// overflow if the length of the slice is larger than `MAX_LEN`, which is why
17+
/// it is marked as `unsafe`.
18+
///
19+
///
20+
/// Typically you should avoid creating your own `Short`s, instead create a
21+
/// `JsonValue` (either using `"foo".into()` or `JsonValue::from("foo")`) out
22+
/// of a slice. This will automatically decide on `String` or `Short` for you.
2023
#[inline]
2124
pub unsafe fn from_slice(slice: &str) -> Self {
2225
let mut short = Short {
@@ -41,6 +44,12 @@ impl Short {
4144
}
4245
}
4346

47+
impl PartialEq for Short {
48+
fn eq(&self, other: &Short) -> bool {
49+
self.as_str() == other.as_str()
50+
}
51+
}
52+
4453
impl fmt::Debug for Short {
4554
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4655
fmt::Debug::fmt(self.as_str(), f)

0 commit comments

Comments
 (0)