Skip to content
Myr

lib.rs

This file

Path

serde_core/src/lib.rs

116 lines · 4.0 KiB · Rust

Last changed by

Feature never_type has been stabilized in nightlyDavid Tolnaybefore adoption50b6384

History of this file

Take it

1//! Serde is a framework for ***ser***ializing and ***de***serializing Rust data2//! structures efficiently and generically.3//!4//! The `serde_core` crate contains Serde's trait definitions with **no support5//! for #\[derive()\]**.6//!7//! In crates that derive an implementation of `Serialize` or `Deserialize`, you8//! must depend on the [`serde`] crate, not `serde_core`.9//!10//! [`serde`]: https://crates.io/crates/serde11//!12//! In crates that handwrite implementations of Serde traits, or only use them13//! as trait bounds, depending on `serde_core` is permitted. But `serde`14//! re-exports all of these traits and can be used for this use case too. If in15//! doubt, disregard `serde_core` and always use `serde`.16//!17//! Crates that depend on `serde_core` instead of `serde` are able to compile in18//! parallel with `serde_derive` even when `serde`'s "derive" feature is turned on,19//! as shown in the following build timings.20//!21//! <br>22//!23//! <table>24//! <tr><td align="center">When <code>serde_json</code> depends on <code>serde</code></td></tr>25//! <tr><td><img src="https://github.com/user-attachments/assets/78dc179c-6ab1-4059-928c-1474b0d9d0bb"></td></tr>26//! </table>27//!28//! <br>29//!30//! <table>31//! <tr><td align="center">When <code>serde_json</code> depends on <code>serde_core</code></td></tr>32//! <tr><td><img src="https://github.com/user-attachments/assets/6b6cff5e-3e45-4ac7-9db1-d99ee8b9f5f7"></td></tr>33//! </table>3435////////////////////////////////////////////////////////////////////////////////3637// Serde types in rustdoc of other crates get linked to here.38#![doc(html_root_url = "https://docs.rs/serde_core/1.0.229")]39// Support using Serde without the standard library!40#![cfg_attr(not(feature = "std"), no_std)]41// Show which crate feature enables conditionally compiled APIs in documentation.42#![cfg_attr(docsrs, feature(doc_cfg, rustdoc_internals))]43#![cfg_attr(docsrs, allow(internal_features))]44#![allow(unknown_lints, bare_trait_objects, deprecated)]45// Ignored clippy and clippy_pedantic lints46#![allow(47    // clippy bug: https://github.com/rust-lang/rust-clippy/issues/570448    clippy::unnested_or_patterns,49    // clippy bug: https://github.com/rust-lang/rust-clippy/issues/776850    clippy::semicolon_if_nothing_returned,51    // not available in our oldest supported compiler52    clippy::empty_enums,53    clippy::type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/877254    // integer and float ser/de requires these sorts of casts55    clippy::cast_possible_truncation,56    clippy::cast_possible_wrap,57    clippy::cast_precision_loss,58    clippy::cast_sign_loss,59    // things are often more readable this way60    clippy::cast_lossless,61    clippy::module_name_repetitions,62    clippy::single_match_else,63    clippy::type_complexity,64    clippy::use_self,65    clippy::zero_prefixed_literal,66    // correctly used67    clippy::derive_partial_eq_without_eq,68    clippy::enum_glob_use,69    clippy::explicit_auto_deref,70    clippy::incompatible_msrv,71    clippy::let_underscore_untyped,72    clippy::map_err_ignore,73    clippy::new_without_default,74    clippy::result_unit_err,75    clippy::wildcard_imports,76    // not practical77    clippy::needless_pass_by_value,78    clippy::similar_names,79    clippy::too_many_lines,80    // preference81    clippy::doc_markdown,82    clippy::elidable_lifetime_names,83    clippy::needless_lifetimes,84    clippy::unseparated_literal_suffix,85    // false positive86    clippy::needless_doctest_main,87    // noisy88    clippy::missing_errors_doc,89    clippy::must_use_candidate,90)]91// Restrictions92#![deny(clippy::question_mark_used)]93// Rustc lints.94#![deny(missing_docs, unused_imports)]9596////////////////////////////////////////////////////////////////////////////////9798#[cfg(feature = "alloc")]99extern crate alloc;100101#[macro_use]102mod crate_root;103#[macro_use]104mod macros;105106crate_root!();107108#[macro_export]109#[doc(hidden)]110macro_rules! __require_serde_not_serde_core {111    () => {112        ::core::compile_error!(113            "Serde derive requires a dependency on the serde crate, not serde_core"114        );115    };116}