Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Extract serde_core out of serde crate #2608

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
29309ef
Extract serde-core out of serde.
osiewicz Sep 4, 2023
248db9b
doc: Alias most macros to use serde_core as serde
osiewicz Sep 4, 2023
4cc50b8
derive: Refer to serde_core instead of serde.
osiewicz Sep 4, 2023
d68d6ce
chore: Move serde_core's docstring into serde
osiewicz Sep 4, 2023
12e80bb
Revert "derive: Refer to serde_core instead of serde."
osiewicz Sep 4, 2023
2258bb4
chore: rely on serde in dev of serde-core
osiewicz Sep 4, 2023
6207f19
chore: fix no_std build
osiewicz Sep 4, 2023
61c756e
test_suite: Update paths to constrain function
osiewicz Sep 4, 2023
043988d
Revert "doc: Alias most macros to use serde_core as serde"
osiewicz Sep 9, 2023
57176ff
Merge branch 'master' into extract_serde_core
osiewicz Oct 19, 2023
39bbd08
fixup! Merge branch 'master' into extract_serde_core
osiewicz Oct 19, 2023
75f9842
Merge branch 'master' into extract_serde_core
osiewicz Oct 30, 2023
1a42cf6
Remove unused imports
osiewicz Oct 30, 2023
b5c0a1a
fixup! Remove unused imports
osiewicz Oct 30, 2023
6adfbd1
Pin serde-core version.
osiewicz Feb 25, 2024
0b77515
Fix up metadata in serde_core's Cargo.toml
osiewicz Feb 25, 2024
c0a3c74
Ensure that license files are symlinks
osiewicz Feb 25, 2024
750c8a0
Point 'readme' in serde-core's Cargo.toml to root crates-io.md
osiewicz Feb 27, 2024
0189f78
Point .documentation to serde_core
osiewicz Feb 27, 2024
830407d
Update description
osiewicz Feb 27, 2024
ac94112
Merge branch 'master' into extract_serde_core
osiewicz Feb 27, 2024
4a094f3
Migrate rustdoc changes after the merge
osiewicz Feb 27, 2024
aa67cff
Bump serde_core version to match serde
osiewicz Feb 27, 2024
da1aed2
Revert unintentional change to serde_derive' Cargo.toml
osiewicz Feb 27, 2024
fcb996b
Bring back doc_cfg and html_root_url in serde
osiewicz Feb 27, 2024
ed3f536
Reword crate-level docs for serde core
osiewicz Feb 27, 2024
49d028d
Merge branch 'master' into extract_serde_core
osiewicz Feb 29, 2024
5d10e39
Merge branch 'master' into extract_serde_core
osiewicz Mar 5, 2024
1de611d
Start moving __private into serde
osiewicz Mar 7, 2024
173bf76
Merge branch 'master' into extract_serde_core
osiewicz Apr 15, 2024
51785bb
Fix up CI
osiewicz Apr 15, 2024
73d2a32
Another fixup to CI
osiewicz Apr 24, 2024
e393bcc
Merge branch 'master' into extract_serde_core
osiewicz Apr 24, 2024
82f4143
Revert change to tests, remove redundant imports
osiewicz Apr 24, 2024
c381b0a
Further test fixes
osiewicz Apr 24, 2024
23e9589
Add missing export
osiewicz Apr 24, 2024
b3bacee
change export to refer to self
osiewicz Apr 25, 2024
1ed3e2d
Merge branch 'master' into extract_serde_core
osiewicz May 3, 2024
2416b69
Mark tri as macro_export
osiewicz May 3, 2024
d7193bd
Remove TryFrom import
osiewicz May 3, 2024
a4265ec
Revert "Remove TryFrom import"
osiewicz May 3, 2024
f0649d8
Reintroduce build script for serde
osiewicz May 3, 2024
8255dac
doc(hidden) tri macro
osiewicz May 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
@@ -1,6 +1,7 @@
[workspace]
members = [
"serde",
"serde_core",
"serde_derive",
"serde_derive_internals",
"test_suite",
Expand Down
15 changes: 9 additions & 6 deletions serde/Cargo.toml
@@ -1,8 +1,10 @@
[package]
name = "serde"
version = "1.0.197"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
build = "build.rs"
authors = [
"Erick Tryzelaar <erick.tryzelaar@gmail.com>",
"David Tolnay <dtolnay@gmail.com>",
]
categories = ["encoding", "no-std", "no-std::no-alloc"]
description = "A generic serialization/deserialization framework"
documentation = "https://docs.rs/serde"
Expand All @@ -16,6 +18,7 @@ rust-version = "1.31"

[dependencies]
serde_derive = { version = "1", optional = true, path = "../serde_derive" }
serde_core = { version = "=1.0.197", path = "../serde_core", default-features = false }

[dev-dependencies]
serde_derive = { version = "1", path = "../serde_derive" }
Expand Down Expand Up @@ -50,20 +53,20 @@ derive = ["serde_derive"]

# Provide impls for common standard library types like Vec<T> and HashMap<K, V>.
# Requires a dependency on the Rust standard library.
std = []
std = ["serde_core/std"]

# Provide impls for types that require unstable functionality. For tracking and
# discussion of unstable functionality please refer to this issue:
#
# https://github.com/serde-rs/serde/issues/812
unstable = []
unstable = ["serde_core/unstable"]

# Provide impls for types in the Rust core allocation and collections library
# including String, Box<T>, Vec<T>, and Cow<T>. This is a subset of std but may
# be enabled without depending on all of std.
alloc = []
alloc = ["serde_core/alloc"]

# Opt into impls for Rc<T> and Arc<T>. Serializing and deserializing these types
# does not preserve identity and may result in multiple copies of the same data.
# Be sure that this is what you want before enabling this feature.
rc = []
rc = ["serde_core/rc"]
226 changes: 1 addition & 225 deletions serde/src/lib.rs
Expand Up @@ -92,229 +92,10 @@
//! [Hjson]: https://github.com/Canop/deser-hjson
//! [CSV]: https://docs.rs/csv

////////////////////////////////////////////////////////////////////////////////

// Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde/1.0.197")]
// Support using Serde without the standard library!
#![cfg_attr(not(feature = "std"), no_std)]
// Show which crate feature enables conditionally compiled APIs in documentation.
#![cfg_attr(doc_cfg, feature(doc_cfg))]
// Unstable functionality only if the user asks for it. For tracking and
// discussion of these features please refer to this issue:
//
// https://github.com/serde-rs/serde/issues/812
#![cfg_attr(feature = "unstable", feature(error_in_core, never_type))]
#![allow(unknown_lints, bare_trait_objects, deprecated)]
// Ignored clippy and clippy_pedantic lints
#![allow(
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/5704
clippy::unnested_or_patterns,
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/7768
clippy::semicolon_if_nothing_returned,
// not available in our oldest supported compiler
clippy::empty_enum,
clippy::type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/8772
// integer and float ser/de requires these sorts of casts
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::cast_sign_loss,
// things are often more readable this way
clippy::cast_lossless,
clippy::module_name_repetitions,
clippy::single_match_else,
clippy::type_complexity,
clippy::use_self,
clippy::zero_prefixed_literal,
// correctly used
clippy::derive_partial_eq_without_eq,
clippy::enum_glob_use,
clippy::explicit_auto_deref,
clippy::incompatible_msrv,
clippy::let_underscore_untyped,
clippy::map_err_ignore,
clippy::new_without_default,
clippy::result_unit_err,
clippy::wildcard_imports,
// not practical
clippy::needless_pass_by_value,
clippy::similar_names,
clippy::too_many_lines,
// preference
clippy::doc_markdown,
clippy::unseparated_literal_suffix,
// false positive
clippy::needless_doctest_main,
// noisy
clippy::missing_errors_doc,
clippy::must_use_candidate,
)]
// Restrictions
#![deny(clippy::question_mark_used)]
// Rustc lints.
#![deny(missing_docs, unused_imports)]

////////////////////////////////////////////////////////////////////////////////

#[cfg(feature = "alloc")]
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 {
mod core {
#[cfg(not(feature = "std"))]
pub use core::*;
#[cfg(feature = "std")]
pub use std::*;
}

pub use self::core::{f32, f64};
pub use self::core::{i16, i32, i64, i8, isize};
pub use self::core::{iter, num, ptr, str};
pub use self::core::{u16, u32, u64, u8, usize};

#[cfg(any(feature = "std", feature = "alloc"))]
pub use self::core::{cmp, mem, slice};

pub use self::core::cell::{Cell, RefCell};
pub use self::core::clone;
pub use self::core::cmp::Reverse;
pub use self::core::convert;
pub use self::core::default;
pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};
pub use self::core::marker::{self, PhantomData};
pub use self::core::num::Wrapping;
pub use self::core::ops::{Bound, Range, RangeFrom, RangeInclusive, RangeTo};
pub use self::core::option;
pub use self::core::result;
pub use self::core::time::Duration;

#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::borrow::{Cow, ToOwned};
#[cfg(feature = "std")]
pub use std::borrow::{Cow, ToOwned};

#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::string::{String, ToString};
#[cfg(feature = "std")]
pub use std::string::{String, ToString};

#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::vec::Vec;
#[cfg(feature = "std")]
pub use std::vec::Vec;

#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::boxed::Box;
#[cfg(feature = "std")]
pub use std::boxed::Box;

#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
pub use alloc::rc::{Rc, Weak as RcWeak};
#[cfg(all(feature = "rc", feature = "std"))]
pub use std::rc::{Rc, Weak as RcWeak};

#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
pub use alloc::sync::{Arc, Weak as ArcWeak};
#[cfg(all(feature = "rc", feature = "std"))]
pub use std::sync::{Arc, Weak as ArcWeak};

#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
#[cfg(feature = "std")]
pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};

#[cfg(all(not(no_core_cstr), not(feature = "std")))]
pub use self::core::ffi::CStr;
#[cfg(feature = "std")]
pub use std::ffi::CStr;

#[cfg(all(not(no_core_cstr), feature = "alloc", not(feature = "std")))]
pub use alloc::ffi::CString;
#[cfg(feature = "std")]
pub use std::ffi::CString;

#[cfg(feature = "std")]
pub use std::{error, net};

#[cfg(feature = "std")]
pub use std::collections::{HashMap, HashSet};
#[cfg(feature = "std")]
pub use std::ffi::{OsStr, OsString};
#[cfg(feature = "std")]
pub use std::hash::{BuildHasher, Hash};
#[cfg(feature = "std")]
pub use std::io::Write;
#[cfg(feature = "std")]
pub use std::path::{Path, PathBuf};
#[cfg(feature = "std")]
pub use std::sync::{Mutex, RwLock};
#[cfg(feature = "std")]
pub use std::time::{SystemTime, UNIX_EPOCH};

#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
pub use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
AtomicUsize, Ordering,
};
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
pub use std::sync::atomic::{AtomicI64, AtomicU64};

#[cfg(all(feature = "std", not(no_target_has_atomic)))]
pub use std::sync::atomic::Ordering;
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "8"))]
pub use std::sync::atomic::{AtomicBool, AtomicI8, AtomicU8};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "16"))]
pub use std::sync::atomic::{AtomicI16, AtomicU16};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "32"))]
pub use std::sync::atomic::{AtomicI32, AtomicU32};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "64"))]
pub use std::sync::atomic::{AtomicI64, AtomicU64};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))]
pub use std::sync::atomic::{AtomicIsize, AtomicUsize};
}

// None of this crate's error handling needs the `From::from` error conversion
// performed implicitly by the `?` operator or the standard library's `try!`
// macro. This simplified macro gives a 5.5% improvement in compile time
// compared to standard `try!`, and 9% improvement compared to `?`.
macro_rules! tri {
($expr:expr) => {
match $expr {
Ok(val) => val,
Err(err) => return Err(err),
}
};
}

////////////////////////////////////////////////////////////////////////////////

#[macro_use]
mod macros;

#[macro_use]
mod integer128;

pub mod de;
pub mod ser;

#[doc(inline)]
pub use crate::de::{Deserialize, Deserializer};
#[doc(inline)]
pub use crate::ser::{Serialize, Serializer};

// Used by generated code and doc tests. Not public API.
#[doc(hidden)]
#[path = "private/mod.rs"]
pub mod __private;

#[path = "de/seed.rs"]
mod seed;

#[cfg(not(any(feature = "std", feature = "unstable")))]
mod std_error;
pub use serde_core::*;

// Re-export #[derive(Serialize, Deserialize)].
//
Expand All @@ -328,8 +109,3 @@ extern crate serde_derive;
#[cfg(feature = "serde_derive")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
pub use serde_derive::{Deserialize, Serialize};

#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
mod actually_private {
pub struct T;
}
58 changes: 58 additions & 0 deletions serde_core/Cargo.toml
@@ -0,0 +1,58 @@
[package]
name = "serde_core"
version = "1.0.197" # remember to update html_root_url and serde_derive dependency
authors = [
"Erick Tryzelaar <erick.tryzelaar@gmail.com>",
"David Tolnay <dtolnay@gmail.com>",
]
build = "build.rs"
categories = ["encoding", "no-std", "no-std::no-alloc"]
description = "Core functionalities and abstractions for the Serde serialization/deserialization framework"
documentation = "https://docs.rs/serde_core"
edition = "2018"
homepage = "https://serde.rs"
keywords = ["serde", "serialization", "no_std"]
license = "MIT OR Apache-2.0"
readme = "../crates-io.md"
repository = "https://github.com/serde-rs/serde"
rust-version = "1.31"

[dev-dependencies]
serde_derive = { version = "1", path = "../serde_derive" }
serde = { version = "1", path = "../serde" }

[lib]
doc-scrape-examples = false

[package.metadata.playground]
features = ["rc"]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]

### FEATURES #################################################################

[features]
default = ["std"]


# Provide impls for common standard library types like Vec<T> and HashMap<K, V>.
# Requires a dependency on the Rust standard library.
std = []

# Provide impls for types that require unstable functionality. For tracking and
# discussion of unstable functionality please refer to this issue:
#
# https://github.com/serde-rs/serde/issues/812
unstable = []

# Provide impls for types in the Rust core allocation and collections library
# including String, Box<T>, Vec<T>, and Cow<T>. This is a subset of std but may
# be enabled without depending on all of std.
alloc = []

# Opt into impls for Rc<T> and Arc<T>. Serializing and deserializing these types
# does not preserve identity and may result in multiple copies of the same data.
# Be sure that this is what you want before enabling this feature.
rc = []
1 change: 1 addition & 0 deletions serde_core/LICENSE-APACHE
1 change: 1 addition & 0 deletions serde_core/LICENSE-MIT
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.