Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions serde/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use std::str;

const PRIVATE: &str = "\
#[doc(hidden)]
pub mod __private$$ {
#[doc(hidden)]
pub use crate::private::*;
}
use serde_core::__private$$ as serde_core_private;
";

// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script.
fn main() {
println!("cargo:rerun-if-changed=build.rs");

let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let patch_version = env::var("CARGO_PKG_VERSION_PATCH").unwrap();
let module = PRIVATE.replace("$$", &patch_version);
fs::write(out_dir.join("private.rs"), module).unwrap();

let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
Expand Down
5 changes: 3 additions & 2 deletions serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ mod integer128;

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

include!(concat!(env!("OUT_DIR"), "/private.rs"));

// Re-export #[derive(Serialize, Deserialize)].
//
Expand Down
6 changes: 3 additions & 3 deletions serde/src/private/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use self::content::{
UntaggedUnitVisitor,
};

pub use serde_core::__private::InPlaceSeed;
pub use crate::serde_core_private::InPlaceSeed;

/// If the missing field is of type `Option<T>` then treat is as `None`,
/// otherwise it is an error.
Expand Down Expand Up @@ -216,8 +216,8 @@ mod content {
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
MapAccess, SeqAccess, Unexpected, Visitor,
};
use serde_core::__private::size_hint;
pub use serde_core::__private::Content;
use crate::serde_core_private::size_hint;
pub use crate::serde_core_private::Content;

pub fn content_as_str<'a, 'de>(content: &'a Content<'de>) -> Option<&'a str> {
match *content {
Expand Down
2 changes: 1 addition & 1 deletion serde/src/private/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use crate::lib::option::Option::{self, None, Some};
pub use crate::lib::ptr;
pub use crate::lib::result::Result::{self, Err, Ok};

pub use serde_core::__private::string::from_utf8_lossy;
pub use crate::serde_core_private::string::from_utf8_lossy;

#[cfg(any(feature = "alloc", feature = "std"))]
pub use crate::lib::{ToString, Vec};
15 changes: 15 additions & 0 deletions serde_core/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use std::str;

const PRIVATE: &str = "\
#[doc(hidden)]
pub mod __private$$ {
#[doc(hidden)]
pub use crate::private::*;
}
";

// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script.
fn main() {
println!("cargo:rerun-if-changed=build.rs");

let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let patch_version = env::var("CARGO_PKG_VERSION_PATCH").unwrap();
let module = PRIVATE.replace("$$", &patch_version);
fs::write(out_dir.join("private.rs"), module).unwrap();

let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
Expand Down
15 changes: 12 additions & 3 deletions serde_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,18 @@ pub use crate::ser::{Serialize, Serializer};

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

// Used by declarative macro generated code. Not public API.
#[doc(hidden)]
pub mod __private {
#[doc(hidden)]
pub use crate::private::doc;
#[doc(hidden)]
pub use core::result::Result;
}

include!(concat!(env!("OUT_DIR"), "/private.rs"));

#[cfg(all(not(feature = "std"), no_core_error))]
mod std_error;
Expand Down
Loading
Loading