summaryrefslogtreecommitdiffstats
path: root/third_party/rust/serde/src/export.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/serde/src/export.rs')
-rw-r--r--third_party/rust/serde/src/export.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/third_party/rust/serde/src/export.rs b/third_party/rust/serde/src/export.rs
new file mode 100644
index 0000000000..caa1f4dc22
--- /dev/null
+++ b/third_party/rust/serde/src/export.rs
@@ -0,0 +1,39 @@
+pub use lib::clone::Clone;
+pub use lib::convert::{From, Into};
+pub use lib::default::Default;
+pub use lib::fmt::{self, Formatter};
+pub use lib::marker::PhantomData;
+pub use lib::option::Option::{self, None, Some};
+pub use lib::result::Result::{self, Err, Ok};
+
+pub use self::string::from_utf8_lossy;
+
+#[cfg(any(feature = "alloc", feature = "std"))]
+pub use lib::{ToString, Vec};
+
+#[cfg(core_try_from)]
+pub use lib::convert::TryFrom;
+
+mod string {
+ use lib::*;
+
+ #[cfg(any(feature = "std", feature = "alloc"))]
+ pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<str> {
+ String::from_utf8_lossy(bytes)
+ }
+
+ // The generated code calls this like:
+ //
+ // let value = &_serde::export::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")))]
+ 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}")
+ }
+}