Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Add some small niceties to our OOM-handling `String` (#12556)

Nick Fitzgerald285a6dc64060
diff --git a/crates/core/src/alloc/string.rs b/crates/core/src/alloc/string.rs
index e25e6307de..9d369d3209 100644
--- a/crates/core/src/alloc/string.rs
+++ b/crates/core/src/alloc/string.rs
@@ -7,7 +7,7 @@ use std_alloc::{alloc::Layout, boxed::Box, string as inner};
/// A newtype wrapper around [`std::string::String`] that only exposes
/// fallible-allocation methods.
-#[derive(Default)]
+#[derive(Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct String {
inner: inner::String,
}
@@ -121,6 +121,12 @@ impl String {
self.inner.capacity()
}
+ /// Same as [`std::string::String::as_str`].
+ #[inline]
+ pub const fn as_str(&self) -> &str {
+ self.inner.as_str()
+ }
+
/// Same as [`std::string::String::reserve`] but returns an error on
/// allocation failure.
#[inline]