MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / into_boxed_str

Method into_boxed_str

crates/core/src/alloc/string.rs:285–297  ·  view source on GitHub ↗

Same as [`std::string::String::into_boxed_str`] but returns an error on allocation failure.

(mut self)

Source from the content-addressed store, hash-verified

283 /// Same as [`std::string::String::into_boxed_str`] but returns an error on
284 /// allocation failure.
285 pub fn into_boxed_str(mut self) -> Result<Box<str>, OutOfMemory> {
286 self.shrink_to_fit()?;
287
288 let (ptr, len, cap) = self.into_raw_parts();
289 debug_assert_eq!(len, cap);
290 let ptr = str_ptr_from_raw_parts(ptr, len);
291
292 // SAFETY: The `ptr` is allocated with the global allocator and points
293 // to a valid block of utf8.
294 let boxed = unsafe { Box::from_raw(ptr) };
295
296 Ok(boxed)
297 }
298}

Callers 3

visit_seqMethod · 0.80
insertMethod · 0.80

Calls 4

str_ptr_from_raw_partsFunction · 0.85
OkFunction · 0.85
shrink_to_fitMethod · 0.45
into_raw_partsMethod · 0.45

Tested by 1