use std::{char, f64, fmt, str};
use std;
-use Encodable;
+use crate::Encodable;
/// Represents a json value
#[derive(Clone, PartialEq, PartialOrd, Debug)]
pub struct PrettyJson<'a> { inner: &'a Json }
-pub struct AsJson<'a, T: 'a> { inner: &'a T }
-pub struct AsPrettyJson<'a, T: 'a> { inner: &'a T, indent: Option<usize> }
+pub struct AsJson<'a, T> { inner: &'a T }
+pub struct AsPrettyJson<'a, T> { inner: &'a T, indent: Option<usize> }
/// The errors that can arise while parsing a JSON stream.
#[derive(Clone, Copy, PartialEq, Debug)]
}
/// Shortcut function to decode a JSON `&str` into an object
-pub fn decode<T: ::Decodable>(s: &str) -> DecodeResult<T> {
+pub fn decode<T: crate::Decodable>(s: &str) -> DecodeResult<T> {
let json = match from_str(s) {
Ok(x) => x,
Err(e) => return Err(ParseError(e))
};
let mut decoder = Decoder::new(json);
- ::Decodable::decode(&mut decoder)
+ crate::Decodable::decode(&mut decoder)
}
/// Shortcut function to encode a `T` into a JSON `String`
-pub fn encode<T: ::Encodable>(object: &T) -> Result<string::String, EncoderError> {
+pub fn encode<T: crate::Encodable>(object: &T) -> Result<string::String, EncoderError> {
let mut s = String::new();
{
let mut encoder = Encoder::new(&mut s);
}
impl fmt::Display for ErrorCode {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
error_str(*self).fmt(f)
}
}
}
impl fmt::Display for ParserError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// FIXME this should be a nicer error
fmt::Debug::fmt(self, f)
}
}
impl fmt::Display for DecoderError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// FIXME this should be a nicer error
fmt::Debug::fmt(self, f)
}
}
impl fmt::Display for EncoderError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// FIXME this should be a nicer error
fmt::Debug::fmt(self, f)
}
})
}
-impl<'a> ::Encoder for Encoder<'a> {
+impl<'a> crate::Encoder for Encoder<'a> {
type Error = EncoderError;
fn emit_unit(&mut self) -> EncodeResult {
}
}
-impl<'a> ::Encoder for PrettyEncoder<'a> {
+impl<'a> crate::Encoder for PrettyEncoder<'a> {
type Error = EncoderError;
fn emit_unit(&mut self) -> EncodeResult {
}
impl Encodable for Json {
- fn encode<E: ::Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
+ fn encode<E: crate::Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
match *self {
Json::I64(v) => v.encode(e),
Json::U64(v) => v.encode(e),
/// Create an `AsJson` wrapper which can be used to print a value as JSON
/// on-the-fly via `write!`
-pub fn as_json<T>(t: &T) -> AsJson<T> {
+pub fn as_json<T>(t: &T) -> AsJson<'_, T> {
AsJson { inner: t }
}
/// Create an `AsPrettyJson` wrapper which can be used to print a value as JSON
/// on-the-fly via `write!`
-pub fn as_pretty_json<T>(t: &T) -> AsPrettyJson<T> {
+pub fn as_pretty_json<T>(t: &T) -> AsPrettyJson<'_, T> {
AsPrettyJson { inner: t, indent: None }
}
impl Json {
/// Borrow this json object as a pretty object to generate a pretty
/// representation for it via `Display`.
- pub fn pretty(&self) -> PrettyJson {
+ pub fn pretty(&self) -> PrettyJson<'_> {
PrettyJson { inner: self }
}
/// Provides access to the StackElement at a given index.
/// lower indices are at the bottom of the stack while higher indices are
/// at the top.
- pub fn get(&self, idx: usize) -> StackElement {
+ pub fn get(&self, idx: usize) -> StackElement<'_> {
match self.stack[idx] {
InternalIndex(i) => StackElement::Index(i),
InternalKey(start, size) => {
}
}
- /// Compares this stack with an array of StackElements.
- pub fn is_equal_to(&self, rhs: &[StackElement]) -> bool {
+ /// Compares this stack with an array of StackElement<'_>s.
+ pub fn is_equal_to(&self, rhs: &[StackElement<'_>]) -> bool {
if self.stack.len() != rhs.len() { return false; }
for (i, r) in rhs.iter().enumerate() {
if self.get(i) != *r { return false; }
/// Returns true if the bottom-most elements of this stack are the same as
/// the ones passed as parameter.
- pub fn starts_with(&self, rhs: &[StackElement]) -> bool {
+ pub fn starts_with(&self, rhs: &[StackElement<'_>]) -> bool {
if self.stack.len() < rhs.len() { return false; }
for (i, r) in rhs.iter().enumerate() {
if self.get(i) != *r { return false; }
/// Returns true if the top-most elements of this stack are the same as
/// the ones passed as parameter.
- pub fn ends_with(&self, rhs: &[StackElement]) -> bool {
+ pub fn ends_with(&self, rhs: &[StackElement<'_>]) -> bool {
if self.stack.len() < rhs.len() { return false; }
let offset = self.stack.len() - rhs.len();
for (i, r) in rhs.iter().enumerate() {
}
/// Returns the top-most element (if any).
- pub fn top(&self) -> Option<StackElement> {
+ pub fn top(&self) -> Option<StackElement<'_>> {
match self.stack.last() {
None => None,
Some(&InternalIndex(i)) => Some(StackElement::Index(i)),
}
}
-impl ::Decoder for Decoder {
+impl crate::Decoder for Decoder {
type Error = DecoderError;
fn read_nil(&mut self) -> DecodeResult<()> {
Err(ExpectedError("single character string".to_owned(), s.to_string()))
}
- fn read_str(&mut self) -> DecodeResult<Cow<str>> {
+ fn read_str(&mut self) -> DecodeResult<Cow<'_, str>> {
expect!(self.pop(), String).map(Cow::Owned)
}
impl fmt::Display for Json {
/// Encodes a json value into a string
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut shim = FormatShim { inner: f };
let mut encoder = Encoder::new(&mut shim);
match self.encode(&mut encoder) {
impl<'a> fmt::Display for PrettyJson<'a> {
/// Encodes a json value into a string
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut shim = FormatShim { inner: f };
let mut encoder = PrettyEncoder::new(&mut shim);
match self.inner.encode(&mut encoder) {
impl<'a, T: Encodable> fmt::Display for AsJson<'a, T> {
/// Encodes a json value into a string
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut shim = FormatShim { inner: f };
let mut encoder = Encoder::new(&mut shim);
match self.inner.encode(&mut encoder) {
impl<'a, T: Encodable> fmt::Display for AsPrettyJson<'a, T> {
/// Encodes a json value into a string
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut shim = FormatShim { inner: f };
let mut encoder = PrettyEncoder::new(&mut shim);
if let Some(n) = self.indent {
extern crate test;
use self::Animal::*;
use self::test::Bencher;
- use {Encodable, Decodable};
+ use crate::{Encodable, Decodable};
use super::Json::*;
use super::ErrorCode::*;
use super::ParserError::*;
#[test]
fn test_hashmap_with_enum_key() {
use std::collections::HashMap;
- use json;
+ use crate::json;
#[derive(RustcEncodable, Eq, Hash, PartialEq, RustcDecodable, Debug)]
enum Enum {
Foo,