Make from_utf8_lossy private

This commit is contained in:
David Tolnay
2025-09-13 09:55:41 -07:00
parent a16893429b
commit 7f831225a9
5 changed files with 35 additions and 36 deletions
-26
View File
@@ -103,7 +103,6 @@ mod lib {
pub use self::core::{cmp, mem};
pub use self::core::cell::{Cell, RefCell};
pub use self::core::cmp::Reverse;
pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};
pub use self::core::marker::PhantomData;
@@ -203,27 +202,6 @@ mod lib {
#[cfg(not(no_core_num_saturating))]
pub use self::core::num::Saturating;
#[cfg(any(feature = "std", feature = "alloc"))]
#[doc(hidden)]
pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<'_, str> {
String::from_utf8_lossy(bytes)
}
// The generated code calls this like:
//
// let value = &_serde::__private::from_utf8_lossy(bytes);
// Err(_serde::de::Error::unknown_variant(value, VARIANTS))
//
// so it is okay for the return type to be different from the std case as long
// as the above works.
#[cfg(not(any(feature = "std", feature = "alloc")))]
#[doc(hidden)]
pub fn from_utf8_lossy(bytes: &[u8]) -> &str {
// Three unicode replacement characters if it fails. They look like a
// white-on-black question mark. The user will recognize it as invalid
// UTF-8.
str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")
}
}
// None of this crate's error handling needs the `From::from` error conversion
@@ -259,14 +237,10 @@ pub use crate::de::{Deserialize, Deserializer};
#[doc(inline)]
pub use crate::ser::{Serialize, Serializer};
#[doc(hidden)]
pub use lib::from_utf8_lossy;
// Used by generated code. Not public API.
#[doc(hidden)]
#[path = "private/mod.rs"]
pub mod __private;
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
use self::__private as private;
#[path = "de/seed.rs"]