rune::alloc

Struct Box

Source
pub struct Box<T, A = Global>
where A: Allocator, T: ?Sized,
{ /* private fields */ }
Expand description

A pointer type that uniquely owns a heap allocation of type T.

Implementations§

Source§

impl<T> Box<T>

Source

pub fn try_new(value: T) -> Result<Box<T>, AllocError>

Allocates memory on the heap and then places x into it.

This doesn’t actually allocate if T is zero-sized.

§Examples
use rune::alloc::Box;

let five = Box::try_new(5)?;
Source

pub fn try_pin(x: T) -> Result<Pin<Box<T>>, AllocError>

Constructs a new Pin<Box<T>>. If T does not implement Unpin, then x will be pinned in memory and unable to be moved.

Constructing and pinning of the Box can also be done in two steps: Box::try?pin(x) does the same as Box::into_pin([Box::try?new](x)). Consider using into_pin if you already have a Box<T>, or if you want to construct a (pinned) Box in a different way than with Box::try_new.

Source§

impl<T> Box<T>
where T: ?Sized,

Source

pub fn from_std(b: Box<T>) -> Result<Box<T>, Error>

Convert from a std Box.

This causes the underlying allocation to be accounted for by the Global allocator.

A caveat of this method is that the allocation is already in use, but this might still be necessary because we want access to certain methods in std Box such as the ability to coerce to unsized values.

§Examples
use rune::alloc::{Box, Vec};
use rune::alloc::limit;
use std::boxed::Box as StdBox;

assert_eq!(limit::get(), usize::MAX);

let b: StdBox<dyn Iterator<Item = u32>> = StdBox::new(1..3);
let mut b = Box::from_std(b)?;
assert_eq!(b.next(), Some(1));
assert_eq!(b.next(), Some(2));
assert_eq!(b.next(), None);

assert!(limit::get() < usize::MAX);
drop(b);

assert_eq!(limit::get(), usize::MAX);
Source§

impl<T, A> Box<T, A>
where A: Allocator,

Source

pub fn try_new_in(x: T, alloc: A) -> Result<Box<T, A>, AllocError>

Allocates memory in the given allocator then places x into it, returning an error if the allocation fails

This doesn’t actually allocate if T is zero-sized.

§Examples
use rune::alloc::Box;
use rune::alloc::alloc::Global;

let five = Box::try_new_in(5, Global)?;
Source

pub fn try_new_uninit_in(alloc: A) -> Result<Box<MaybeUninit<T>, A>, AllocError>
where A: Allocator,

Constructs a new box with uninitialized contents in the provided allocator, returning an error if the allocation fails

§Examples
use rune::alloc::Box;
use rune::alloc::alloc::Global;

let mut five = Box::<u32>::try_new_uninit_in(Global)?;

let five: Box<u32> = unsafe {
    // Deferred initialization:
    five.as_mut_ptr().write(5);

    five.assume_init()
};

assert_eq!(*five, 5);
Source

pub fn into_inner(boxed: Box<T, A>) -> T

Consumes the Box, returning the wrapped value.

Source§

impl<T, A> Box<T, A>
where A: Allocator, T: ?Sized,

Source

pub fn leak<'a>(b: Box<T, A>) -> &'a mut T
where A: 'a,

Consumes and leaks the Box, returning a mutable reference, &'a mut T. Note that the type T must outlive the chosen lifetime 'a. If the type has only static references, or none at all, then this may be chosen to be 'static.

This function is mainly useful for data that lives for the remainder of the program’s life. Dropping the returned reference will cause a memory leak. If this is not acceptable, the reference should first be wrapped with the Box::from_raw_in function producing a Box. This Box can then be dropped which will properly destroy T and release the allocated memory.

Note: this is an associated function, which means that you have to call it as Box::leak(b) instead of b.leak(). This is so that there is no conflict with a method on the inner type.

§Examples

Simple usage:

use rune::alloc::Box;

let x = Box::try_new(41)?;
let static_ref: &'static mut usize = Box::leak(x);
*static_ref += 1;
assert_eq!(*static_ref, 42);

Unsized data:

use rune::alloc::{try_vec, Box};

let x = try_vec![1, 2, 3].try_into_boxed_slice()?;
let static_ref = Box::leak(x);
static_ref[0] = 4;
assert_eq!(*static_ref, [4, 2, 3]);
Source

pub fn into_pin(boxed: Box<T, A>) -> Pin<Box<T, A>>
where A: 'static,

Converts a Box<T> into a Pin<Box<T>>. If T does not implement Unpin, then *boxed will be pinned in memory and unable to be moved.

This conversion does not allocate on the heap and happens in place.

This is also available via From.

Constructing and pinning a Box with Box::into_pin([Box::try?new](x)) can also be written more concisely using [Box::try?pin](x). This into_pin method is useful if you already have a Box<T>, or you are constructing a (pinned) Box in a different way than with Box::try_new.

§Notes

It’s not recommended that crates add an impl like From<Box<T>> for Pin<T>, as it’ll introduce an ambiguity when calling Pin::from. A demonstration of such a poor impl is shown below.

use rune::alloc::Box;

struct Foo; // A type defined in this crate.
impl From<Box<()>> for Pin<Foo> {
    fn from(_: Box<()>) -> Pin<Foo> {
        Pin::new(Foo)
    }
}

let foo = Box::try_new(())?;
let bar = Pin::from(foo);
Source

pub unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Box<T, A>

Constructs a box from a raw pointer in the given allocator.

After calling this function, the raw pointer is owned by the resulting Box. Specifically, the Box destructor will call the destructor of T and free the allocated memory. For this to be safe, the memory must have been allocated in accordance with the memory layout used by Box .

§Safety

This function is unsafe because improper use may lead to memory problems. For example, a double-free may occur if the function is called twice on the same raw pointer.

§Examples

Recreate a Box which was previously converted to a raw pointer using Box::into_raw_with_allocator:

use rune::alloc::Box;
use rune::alloc::alloc::Global;

let x = Box::try_new_in(5, Global)?;
let (ptr, alloc) = Box::into_raw_with_allocator(x);
let x = unsafe { Box::from_raw_in(ptr, alloc) };

Manually create a Box from scratch by using the system allocator:

use core::alloc::Layout;

use rune::alloc::Box;
use rune::alloc::alloc::{Allocator, Global};

unsafe {
    let ptr = Global.allocate(Layout::new::<i32>())?.as_ptr() as *mut i32;
    // In general .write is required to avoid attempting to destruct
    // the (uninitialized) previous contents of `ptr`, though for this
    // simple example `*ptr = 5` would have worked as well.
    ptr.write(5);
    let x = Box::from_raw_in(ptr, Global);
}
Source

pub fn into_raw_with_allocator(b: Box<T, A>) -> (*mut T, A)

Consumes the Box, returning a wrapped raw pointer and the allocator.

The pointer will be properly aligned and non-null.

After calling this function, the caller is responsible for the memory previously managed by the Box. In particular, the caller should properly destroy T and release the memory, taking into account the memory layout used by Box. The easiest way to do this is to convert the raw pointer back into a Box with the Box::from_raw_in function, allowing the Box destructor to perform the cleanup.

Note: this is an associated function, which means that you have to call it as Box::into_raw_with_allocator(b) instead of b.into_raw_with_allocator(). This is so that there is no conflict with a method on the inner type.

§Examples

Converting the raw pointer back into a Box with Box::from_raw_in for automatic cleanup:

use rune::alloc::{Box, String};
use rune::alloc::alloc::Global;

let x = Box::try_new_in(String::try_from("Hello")?, Global)?;
let (ptr, alloc) = Box::into_raw_with_allocator(x);
let x = unsafe { Box::from_raw_in(ptr, alloc) };

Manual cleanup by explicitly running the destructor and deallocating the memory:

use core::alloc::Layout;
use core::ptr::{self, NonNull};

use rune::alloc::{Box, String};
use rune::alloc::alloc::{Allocator, Global};

let x = Box::try_new_in(String::try_from("Hello")?, Global)?;

let (ptr, alloc) = Box::into_raw_with_allocator(x);

unsafe {
    ptr::drop_in_place(ptr);
    let non_null = NonNull::new_unchecked(ptr);
    alloc.deallocate(non_null.cast(), Layout::new::<String>());
}
Source§

impl<T, A> Box<MaybeUninit<T>, A>
where A: Allocator,

Source

pub unsafe fn assume_init(self) -> Box<T, A>

Converts to Box<T, A>.

§Safety

As with MaybeUninit::assume_init, it is up to the caller to guarantee that the value really is in an initialized state. Calling this when the content is not yet fully initialized causes immediate undefined behavior.

§Examples
use rune::alloc::Box;
use rune::alloc::alloc::Global;

let mut five = Box::<u32>::try_new_uninit_in(Global)?;

let five: Box<u32> = unsafe {
    // Deferred initialization:
    five.as_mut_ptr().write(5);

    five.assume_init()
};

assert_eq!(*five, 5);
Source§

impl<T, A> Box<[T], A>
where A: Allocator,

Source

pub fn try_new_uninit_slice_in( len: usize, alloc: A, ) -> Result<Box<[MaybeUninit<T>], A>, Error>

Constructs a new boxed slice with uninitialized contents. Returns an error if the allocation fails

§Examples
use rune::alloc::Box;
use rune::alloc::alloc::Global;

let mut values = Box::<[u32]>::try_new_uninit_slice_in(3, Global)?;

let values = unsafe {
    // Deferred initialization:
    values[0].as_mut_ptr().write(1);
    values[1].as_mut_ptr().write(2);
    values[2].as_mut_ptr().write(3);
    values.assume_init()
};

assert_eq!(*values, [1, 2, 3]);
Source§

impl<T, A> Box<[MaybeUninit<T>], A>
where A: Allocator,

Source

pub unsafe fn assume_init(self) -> Box<[T], A>

Converts to Box<[T], A>.

§Safety

As with MaybeUninit::assume_init, it is up to the caller to guarantee that the values really are in an initialized state. Calling this when the content is not yet fully initialized causes immediate undefined behavior.

§Examples
use rune::alloc::Box;
use rune::alloc::alloc::Global;

let mut values = Box::<[u32]>::try_new_uninit_slice_in(3, Global)?;

let values = unsafe {
    // Deferred initialization:
    values[0].as_mut_ptr().write(1);
    values[1].as_mut_ptr().write(2);
    values[2].as_mut_ptr().write(3);
    values.assume_init()
};

assert_eq!(*values, [1, 2, 3]);

Trait Implementations§

Source§

impl<T, A> AsMut<T> for Box<T, A>
where A: Allocator, T: ?Sized,

Source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T, A> AsRef<T> for Box<T, A>
where A: Allocator, T: ?Sized,

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, A> Borrow<T> for Box<T, A>
where A: Allocator, T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T, A> BorrowMut<T> for Box<T, A>
where A: Allocator, T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, A> Debug for Box<T, A>
where A: Allocator, T: Debug + ?Sized,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Box<[T]>

Source§

fn default() -> Box<[T]>

Returns the “default value” for a type. Read more
Source§

impl Default for Box<str>

Source§

fn default() -> Box<str>

Returns the “default value” for a type. Read more
Source§

impl<T, A> Deref for Box<T, A>
where A: Allocator, T: ?Sized,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T, A> DerefMut for Box<T, A>
where A: Allocator, T: ?Sized,

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<'de, T> Deserialize<'de> for Box<[T]>
where T: Deserialize<'de>,

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Box<[T]>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'de, T> Deserialize<'de> for Box<T>
where T: Deserialize<'de>,

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Box<T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'de> Deserialize<'de> for Box<str>

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Box<str>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T, A> Display for Box<T, A>
where A: Allocator, T: Display + ?Sized,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T, A> Drop for Box<T, A>
where A: Allocator, T: ?Sized,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, A> From<Box<[T], A>> for Vec<T, A>
where A: Allocator,

Source§

fn from(s: Box<[T], A>) -> Vec<T, A>

Convert a boxed slice into a vector by transferring ownership of the existing heap allocation.

§Examples
use rune::alloc::{Box, Vec};
use rune::alloc::try_vec;

let s: Box<[i32]> = Box::try_from([10, 40, 30])?;
let x: Vec<i32> = Vec::from(s);

assert_eq!(x, [10, 40, 30]);

let s: Box<[i32]> = try_vec![10, 40, 30].try_into_boxed_slice()?;
let x: Vec<i32> = Vec::from(s);

assert_eq!(x, [10, 40, 30]);
Source§

impl From<Box<[Value]>> for OwnedTuple

Source§

fn from(inner: Box<[Value]>) -> Self

Converts to this type from the input type.
Source§

impl From<Box<[u8]>> for Bytes

Source§

fn from(bytes: Box<[u8]>) -> Self

Converts to this type from the input type.
Source§

impl<A> From<Box<str, A>> for Box<[u8], A>
where A: Allocator,

Source§

fn from(value: Box<str, A>) -> Box<[u8], A>

Converts to this type from the input type.
Source§

impl<A> From<Box<str, A>> for String<A>
where A: Allocator,

Source§

fn from(s: Box<str, A>) -> String<A>

Converts the given boxed str slice to a String. It is notable that the str slice is owned.

§Examples

Basic usage:

use rune::alloc::{Box, String};

let s1: String = String::try_from("hello world")?;
let s2: Box<str> = s1.try_into_boxed_str()?;
let s3: String = String::from(s2);

assert_eq!("hello world", s3);
Source§

impl FromValue for Box<Tuple>

Source§

fn from_value(value: Value) -> Result<Self, RuntimeError>

Try to convert to the given type, from the given value.
Source§

impl FromValue for Box<str>

Source§

fn from_value(value: Value) -> Result<Self, RuntimeError>

Try to convert to the given type, from the given value.
Source§

impl<T, A> Hash for Box<T, A>
where A: Allocator, T: Hash + ?Sized,

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoComponent for &Box<str>

Source§

fn as_component_ref(&self) -> ComponentRef<'_>

Convert into a component directly.
Source§

fn into_component(self) -> Result<Component, Error>

Convert into component.
Source§

impl IntoComponent for Box<str>

Source§

fn as_component_ref(&self) -> ComponentRef<'_>

Convert into a component directly.
Source§

fn into_component(self) -> Result<Component, Error>

Convert into component.
Source§

impl MaybeTypeOf for Box<str>

Source§

fn maybe_type_of() -> Result<DocType>

Type information for the given type.
Source§

impl<T> OptionSpanned for Box<T>
where T: OptionSpanned,

Source§

fn option_span(&self) -> Option<Span>

Get the optional span of the type.
Source§

impl<T, A> Ord for Box<T, A>
where A: Allocator, T: Ord + ?Sized,

Source§

fn cmp(&self, other: &Box<T, A>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> Parse for Box<T>
where T: Parse,

Parse implementation for something that is boxed.

Source§

fn parse(parser: &mut Parser<'_>) -> Result<Self>

Parse the current item from the parser.
Source§

impl<T, A> PartialEq for Box<T, A>
where A: Allocator, T: PartialEq + ?Sized,

Source§

fn eq(&self, other: &Box<T, A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, A> PartialOrd for Box<T, A>
where A: Allocator, T: PartialOrd + ?Sized,

Source§

fn partial_cmp(&self, other: &Box<T, A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Peek for Box<T>
where T: Peek,

Peek implementation for something that is boxed.

Source§

fn peek(p: &mut Peeker<'_>) -> bool

Peek the parser for the given token.
Source§

impl<T> Serialize for Box<T>
where T: Serialize + ?Sized,

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Spanned for Box<T>
where T: Spanned,

Source§

fn span(&self) -> Span

Get the span of the type.
Source§

impl<T> ToTokens for Box<T>
where T: ToTokens,

Source§

fn to_tokens( &self, context: &mut MacroContext<'_, '_, '_>, stream: &mut TokenStream, ) -> Result<()>

Turn the current item into tokens.
Source§

impl ToValue for Box<str>

Source§

fn to_value(self) -> Result<Value, RuntimeError>

Convert into a value.
Source§

impl<T, A> TryClone for Box<[T], A>
where A: Allocator + Clone, T: TryClone,

Source§

fn try_clone(&self) -> Result<Box<[T], A>, Error>

Try to clone the current value, raising an allocation error if it’s unsuccessful.
Source§

fn try_clone_from(&mut self, source: &Self) -> Result<(), Error>

Performs copy-assignment from source. Read more
Source§

impl<A> TryClone for Box<Path, A>
where A: Allocator + Clone,

Source§

fn try_clone(&self) -> Result<Box<Path, A>, Error>

Try to clone the current value, raising an allocation error if it’s unsuccessful.
Source§

fn try_clone_from(&mut self, source: &Self) -> Result<(), Error>

Performs copy-assignment from source. Read more
Source§

impl<T, A> TryClone for Box<T, A>
where A: Allocator + Clone, T: TryClone,

Source§

fn try_clone(&self) -> Result<Box<T, A>, Error>

Try to clone the current value, raising an allocation error if it’s unsuccessful.
Source§

fn try_clone_from(&mut self, source: &Self) -> Result<(), Error>

Performs copy-assignment from source. Read more
Source§

impl<A> TryClone for Box<str, A>
where A: Allocator + Clone,

Source§

fn try_clone(&self) -> Result<Box<str, A>, Error>

Try to clone the current value, raising an allocation error if it’s unsuccessful.
Source§

fn try_clone_from(&mut self, source: &Self) -> Result<(), Error>

Performs copy-assignment from source. Read more
Source§

impl TryFrom<&[u8]> for Box<[u8]>

Source§

fn try_from(values: &[u8]) -> Result<Box<[u8]>, Error>

Converts a &[u8] into a Box<[u8]>.

§Examples
use rune::alloc::Box;

let s: Box<[u8]> = Box::try_from(&b"Hello World"[..])?;
assert_eq!(s.as_ref(), b"Hello World");
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl TryFrom<&Path> for Box<Path>

Source§

fn try_from(path: &Path) -> Result<Box<Path>, Error>

Converts a &[u8] into a Box<[u8]>.

§Examples
use std::path::Path;
use rune::alloc::Box;

let path = Path::new("foo/bar");

let s: Box<Path> = Box::try_from(path)?;
assert_eq!(s.as_ref(), Path::new("foo/bar"));
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl TryFrom<&str> for Box<str>

Source§

fn try_from(values: &str) -> Result<Box<str>, Error>

Converts a &str into a Box<str>.

§Examples
use rune::alloc::Box;

let s: Box<str> = Box::try_from("Hello World")?;
assert_eq!(s.as_ref(), "Hello World");
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl<T, const N: usize> TryFrom<[T; N]> for Box<[T]>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(values: [T; N]) -> Result<Box<[T]>, Error>

Performs the conversion.
Source§

impl TryFrom<Box<[ConstValue]>> for OwnedTuple

Source§

type Error = RuntimeError

The type returned in the event of a conversion error.
Source§

fn try_from(inner: Box<[ConstValue]>) -> Result<Self, RuntimeError>

Performs the conversion.
Source§

impl<T> TryFrom<Box<[T]>> for Box<[T]>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(values: Box<[T]>) -> Result<Box<[T]>, Error>

Performs the conversion.
Source§

impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]>

Source§

fn try_from( boxed_slice: Box<[T]>, ) -> Result<Box<[T; N]>, <Box<[T; N]> as TryFrom<Box<[T]>>>::Error>

Attempts to convert a Box<[T]> into a Box<[T; N]>.

The conversion occurs in-place and does not require a new memory allocation.

§Errors

Returns the old Box<[T]> in the Err variant if boxed_slice.len() does not equal N.

Source§

type Error = Box<[T]>

The type returned in the event of a conversion error.
Source§

impl TryFrom<Cow<'_, str>> for Box<str>

Source§

fn try_from(s: Cow<'_, str>) -> Result<Box<str>, Error>

Converts the given String to a boxed str slice that is owned.

§Examples
use rune::alloc::Box;
use rune::alloc::borrow::Cow;

let s2: Box<str> = Box::try_from(Cow::Borrowed("Hello World"))?;

assert_eq!("Hello World", s2.as_ref());
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl<A> TryFrom<String<A>> for Box<str, A>
where A: Allocator,

Source§

fn try_from(s: String<A>) -> Result<Box<str, A>, Error>

Converts the given String to a boxed str slice that is owned.

§Examples
use rune::alloc::{String, Box};

let s1: String = String::try_from("Hello World")?;
let s2: Box<str> = Box::try_from("Hello World")?;

assert_eq!("Hello World", s2.as_ref());
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl TryFrom<String> for Box<str>

Source§

fn try_from(string: String) -> Result<Box<str>, Error>

Converts a std String into a Box<str>.

§Examples
use rune::alloc::Box;

let s = String::from("Hello World");
let s: Box<str> = Box::try_from(s)?;
assert_eq!(s.as_ref(), "Hello World");
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl<T, A> TryFrom<Vec<T, A>> for Box<[T], A>
where A: Allocator,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(vec: Vec<T, A>) -> Result<Box<[T], A>, Error>

Performs the conversion.
Source§

impl<T, A> TryFromIteratorIn<T, A> for Box<[T], A>
where A: Allocator,

Source§

fn try_from_iter_in<I>(iter: I, alloc: A) -> Result<Box<[T], A>, Error>
where I: IntoIterator<Item = T>,

Creates a value from an iterator within an allocator.
Source§

impl TypeHash for Box<str>

Source§

const HASH: Hash = _

The complete type hash of the type including type parameters which uniquely identifiers a given type. Read more
Source§

impl TypeOf for Box<str>

Source§

const STATIC_TYPE_INFO: AnyTypeInfo = _

Access diagnostical type information for the current type. Read more
Source§

const PARAMETERS: Hash = Hash::EMPTY

Type parameters for the type. Read more
Source§

fn type_info() -> TypeInfo

Get type info associated with the current type.
Source§

impl<T, A> Eq for Box<T, A>
where A: Allocator, T: Eq + ?Sized,

Source§

impl<T, A> Unpin for Box<T, A>
where A: Allocator + 'static, T: ?Sized,

Auto Trait Implementations§

§

impl<T, A> Freeze for Box<T, A>
where A: Freeze, T: ?Sized,

§

impl<T, A> RefUnwindSafe for Box<T, A>

§

impl<T, A> Send for Box<T, A>
where A: Send, T: Send + ?Sized,

§

impl<T, A> Sync for Box<T, A>
where A: Sync, T: Sync + ?Sized,

§

impl<T, A> UnwindSafe for Box<T, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> EncodedChars for T
where T: AsRef<str>,

Source§

fn start_ptr(&self) -> *const u8

Pointer to the start of the pattern Read more
Source§

fn limit_ptr(&self) -> *const u8

Pointer to the limit of the pattern buffer Read more
Source§

fn len(&self) -> usize

The length of this buffer
Source§

fn encoding(&self) -> *mut OnigEncodingTypeST

The encoding of the contents of the buffer
Source§

fn is_empty(&self) -> bool

Is the buffer empty?
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToReturn for T
where T: ToValue,

Source§

fn to_return(self) -> VmResult<Value>

Convert something into a return value.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryFromIterator<T> for U

Source§

fn try_from_iter<I>(iter: I) -> Result<U, Error>
where I: IntoIterator<Item = T>,

Creates a value from an iterator within an allocator.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TryToOwned for T
where T: TryClone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn try_to_owned(&self) -> Result<T, Error>

Creates owned data from borrowed data, usually by cloning. Read more
Source§

impl<T> TryToString for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, Error>

Converts the given value to a String. Read more
Source§

impl<T> UnsafeToValue for T
where T: ToValue,

Source§

type Guard = ()

The type used to guard the unsafe value conversion.
Source§

unsafe fn unsafe_to_value( self, ) -> Result<(Value, <T as UnsafeToValue>::Guard), RuntimeError>

Convert into a value. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Formattable for T
where T: Deref, <T as Deref>::Target: Formattable,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> NumBytes for T
where T: Debug + AsRef<[u8]> + AsMut<[u8]> + PartialEq + Eq + PartialOrd + Ord + Hash + Borrow<[u8]> + BorrowMut<[u8]> + ?Sized,

Source§

impl<T> Parsable for T
where T: Deref, <T as Deref>::Target: Parsable,