Eliminate lib module

This commit is contained in:
David Tolnay 2021-12-30 19:55:10 -08:00
parent 31198f589c
commit 5d2cbcdd4b
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
22 changed files with 85 additions and 65 deletions

View File

@ -3,10 +3,16 @@
use crate::error::{Error, ErrorCode, Result};
#[cfg(feature = "float_roundtrip")]
use crate::lexical;
use crate::lib::str::FromStr;
use crate::lib::*;
use crate::number::Number;
use crate::read::{self, Fused, Reference};
use alloc::string::String;
use alloc::vec::Vec;
#[cfg(feature = "float_roundtrip")]
use core::iter;
use core::iter::FusedIterator;
use core::marker::PhantomData;
use core::result;
use core::str::FromStr;
use serde::de::{self, Expected, Unexpected};
use serde::{forward_to_deserialize_any, serde_if_integer128};

View File

@ -1,9 +1,14 @@
//! When serializing or deserializing JSON goes wrong.
use crate::io;
use crate::lib::str::FromStr;
use crate::lib::*;
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use core::fmt::{self, Debug, Display};
use core::result;
use core::str::FromStr;
use serde::{de, ser};
#[cfg(feature = "std")]
use std::error;
/// This type represents all possible errors that can occur when serializing or
/// deserializing JSON data.

View File

@ -1,7 +1,9 @@
//! Reimplements core logic and types from `std::io` in an `alloc`-friendly
//! fashion.
use crate::lib::*;
use alloc::vec::Vec;
use core::fmt::{self, Display};
use core::result;
pub enum ErrorKind {
Other,

View File

@ -12,7 +12,7 @@ use super::float::*;
use super::math::*;
use super::num::*;
use super::rounding::*;
use crate::lib::{cmp, mem};
use core::{cmp, mem};
// MANTISSA

View File

@ -3,7 +3,7 @@
//! Big integer type definition.
use super::math::*;
use crate::lib::Vec;
use alloc::vec::Vec;
/// Storage for a big integer type.
#[derive(Clone, PartialEq, Eq)]

View File

@ -9,7 +9,8 @@
use super::large_powers;
use super::num::*;
use super::small_powers::*;
use crate::lib::{cmp, iter, mem, Vec};
use alloc::vec::Vec;
use core::{cmp, iter, mem};
// ALIASES
// -------

View File

@ -2,7 +2,7 @@
//! Utilities for Rust numbers.
use crate::lib::ops;
use core::ops;
/// Precalculated values of radix**i for i in range [0, arr.len()-1].
/// Each value can be **exactly** represented as that type.

View File

@ -5,7 +5,7 @@
use super::float::ExtendedFloat;
use super::num::*;
use super::shift::*;
use crate::lib::mem;
use core::mem;
// MASKS

View File

@ -3,7 +3,7 @@
//! Bit-shift helpers.
use super::float::ExtendedFloat;
use crate::lib::mem;
use core::mem;
// Shift extended-precision float right `shift` bytes.
#[inline]

View File

@ -360,38 +360,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
////////////////////////////////////////////////////////////////////////////////
extern crate alloc;
/// A facade around all the types we need from the `std`, `core`, and `alloc`
/// crates. This avoids elaborate import wrangling having to happen in every
/// module.
mod lib {
pub use core::cell::{Cell, RefCell};
pub use core::clone::{self, Clone};
pub use core::convert::{self, From, Into};
pub use core::default::{self, Default};
pub use core::fmt::{self, Debug, Display};
pub use core::hash::{self, Hash, Hasher};
pub use core::iter::FusedIterator;
pub use core::marker::{self, PhantomData};
pub use core::ops::{Bound, RangeBounds};
pub use core::result::{self, Result};
pub use core::{borrow, char, cmp, iter, mem, num, ops, slice, str};
pub use alloc::borrow::{Cow, ToOwned};
pub use alloc::boxed::Box;
pub use alloc::collections::{btree_map, BTreeMap};
pub use alloc::string::{String, ToString};
pub use alloc::vec::{self, Vec};
#[cfg(feature = "std")]
pub use std::error;
}
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")]
#[doc(inline)]
pub use crate::de::from_reader;
@ -412,8 +382,8 @@ pub use crate::value::{from_value, to_value, Map, Number, Value};
macro_rules! tri {
($e:expr $(,)?) => {
match $e {
crate::lib::Result::Ok(val) => val,
crate::lib::Result::Err(err) => return crate::lib::Result::Err(err),
core::result::Result::Ok(val) => val,
core::result::Result::Err(err) => return core::result::Result::Err(err),
}
};
}

View File

@ -6,12 +6,19 @@
//! [`BTreeMap`]: https://doc.rust-lang.org/std/collections/struct.BTreeMap.html
//! [`IndexMap`]: https://docs.rs/indexmap/*/indexmap/map/struct.IndexMap.html
use crate::lib::borrow::Borrow;
use crate::lib::iter::FromIterator;
use crate::lib::*;
use crate::value::Value;
use alloc::string::String;
use core::borrow::Borrow;
use core::fmt::{self, Debug};
use core::hash::Hash;
use core::iter::{FromIterator, FusedIterator};
#[cfg(feature = "preserve_order")]
use core::mem;
use core::ops;
use serde::de;
#[cfg(not(feature = "preserve_order"))]
use alloc::collections::{btree_map, BTreeMap};
#[cfg(feature = "preserve_order")]
use indexmap::{self, IndexMap};
@ -165,6 +172,8 @@ impl Map<String, Value> {
no_btreemap_get_key_value,
))]
{
use core::ops::{Bound, RangeBounds};
struct Key<'a, Q: ?Sized>(&'a Q);
impl<'a, Q: ?Sized> RangeBounds<Q> for Key<'a, Q> {
@ -202,7 +211,7 @@ impl Map<String, Value> {
S: Into<String>,
{
#[cfg(not(feature = "preserve_order"))]
use crate::lib::btree_map::Entry as EntryImpl;
use alloc::collections::btree_map::Entry as EntryImpl;
#[cfg(feature = "preserve_order")]
use indexmap::map::Entry as EntryImpl;

View File

@ -1,6 +1,8 @@
use crate::de::ParserNumber;
use crate::error::Error;
use crate::lib::*;
use core::fmt::{self, Debug, Display};
#[cfg(not(feature = "arbitrary_precision"))]
use core::hash::{Hash, Hasher};
use serde::de::{self, Unexpected, Visitor};
use serde::{
forward_to_deserialize_any, serde_if_integer128, Deserialize, Deserializer, Serialize,
@ -286,7 +288,7 @@ impl Number {
}
}
impl fmt::Display for Number {
impl Display for Number {
#[cfg(not(feature = "arbitrary_precision"))]
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self.n {

View File

@ -1,5 +1,6 @@
use crate::error::Error;
use crate::lib::*;
use core::fmt::{self, Debug, Display};
use core::mem;
use serde::de::value::BorrowedStrDeserializer;
use serde::de::{
self, Deserialize, DeserializeSeed, Deserializer, IntoDeserializer, MapAccess, Unexpected,

View File

@ -1,6 +1,9 @@
use crate::error::{Error, ErrorCode, Result};
use crate::lib::ops::Deref;
use crate::lib::*;
use alloc::vec::Vec;
use core::char;
use core::cmp;
use core::ops::Deref;
use core::str;
#[cfg(feature = "std")]
use crate::io;

View File

@ -2,8 +2,10 @@
use crate::error::{Error, ErrorCode, Result};
use crate::io;
use crate::lib::num::FpCategory;
use crate::lib::*;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::fmt::{self, Display};
use core::num::FpCategory;
use serde::ser::{self, Impossible, Serialize};
use serde::serde_if_integer128;

View File

@ -1,9 +1,13 @@
use crate::error::Error;
use crate::lib::str::FromStr;
use crate::lib::*;
use crate::map::Map;
use crate::number::Number;
use crate::value::Value;
use alloc::borrow::{Cow, ToOwned};
use alloc::string::String;
use alloc::vec::{self, Vec};
use core::fmt;
use core::slice;
use core::str::FromStr;
use serde::de::{
self, Deserialize, DeserializeSeed, EnumAccess, Expected, IntoDeserializer, MapAccess,
SeqAccess, Unexpected, VariantAccess, Visitor,

View File

@ -1,8 +1,10 @@
use super::Value;
use crate::lib::iter::FromIterator;
use crate::lib::*;
use crate::map::Map;
use crate::number::Number;
use alloc::borrow::Cow;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::iter::FromIterator;
#[cfg(feature = "arbitrary_precision")]
use serde::serde_if_integer128;

View File

@ -1,6 +1,9 @@
use super::Value;
use crate::lib::*;
use crate::map::Map;
use alloc::borrow::ToOwned;
use alloc::string::String;
use core::fmt::{self, Display};
use core::ops;
/// A type that can be used to index into a `serde_json::Value`.
///
@ -133,14 +136,14 @@ mod private {
pub trait Sealed {}
impl Sealed for usize {}
impl Sealed for str {}
impl Sealed for super::String {}
impl Sealed for alloc::string::String {}
impl<'a, T> Sealed for &'a T where T: ?Sized + Sealed {}
}
/// Used in panic messages.
struct Type<'a>(&'a Value);
impl<'a> fmt::Display for Type<'a> {
impl<'a> Display for Type<'a> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match *self.0 {
Value::Null => formatter.write_str("null"),

View File

@ -92,7 +92,11 @@
use crate::error::Error;
use crate::io;
use crate::lib::*;
use alloc::string::String;
use alloc::vec::Vec;
use core::fmt::{self, Debug, Display};
use core::mem;
use core::str;
use serde::de::DeserializeOwned;
use serde::ser::Serialize;
@ -191,7 +195,7 @@ impl Debug for Value {
}
}
impl fmt::Display for Value {
impl Display for Value {
/// Display a JSON value as a string.
///
/// ```

View File

@ -1,5 +1,5 @@
use super::Value;
use crate::lib::*;
use alloc::string::String;
fn eq_i64(value: &Value, other: i64) -> bool {
value.as_i64().map_or(false, |i| i == other)

View File

@ -1,8 +1,12 @@
use crate::error::{Error, ErrorCode, Result};
use crate::lib::*;
use crate::map::Map;
use crate::number::Number;
use crate::value::{to_value, Value};
use alloc::borrow::ToOwned;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::fmt::Display;
use core::result;
use serde::ser::{Impossible, Serialize};
#[cfg(feature = "arbitrary_precision")]

View File

@ -20,6 +20,8 @@
clippy::wildcard_imports
)]
extern crate alloc;
#[path = "../src/lexical/mod.rs"]
mod lexical;