pub enum FastString {
    Static(&'static str),
    StaticAscii(&'static str),
    Owned(Box<str>),
    Arc(Arc<str>),
}
Expand description

Module names and code can be sourced from strings or bytes that are either owned or borrowed. This enumeration allows us to perform a minimal amount of cloning and format-shifting of the underlying data.

Note that any FastString created from a 'static byte array or string must contain ASCII characters.

Examples of ways to construct a FastString:


let code: FastString = ascii_str!("a string");
let code: FastString = format!("a string").into();

Variants§

§

Static(&'static str)

Created from static data.

§

StaticAscii(&'static str)

Created from static data, known to contain only ASCII chars.

§

Owned(Box<str>)

An owned chunk of data. Note that we use Box rather than Vec to avoid the storage overhead.

§

Arc(Arc<str>)

Implementations§

source§

impl FastString

source

pub const fn from_static(s: &'static str) -> Self

Create a FastString from a static string. The string may contain non-ASCII characters, and if so, will take the slower path when used in v8.

source

pub const fn ensure_static_ascii(s: &'static str) -> Self

Create a FastString from a static string. If the string contains non-ASCII characters, the compiler will abort.

source

pub fn into_cheap_copy(self) -> (Self, Self)

Creates a cheap copy of this FastString, potentially transmuting it to a faster form. Note that this is not a clone operation as it consumes the old FastString.

source

pub fn try_clone(&self) -> Option<Self>

If this FastString is cheaply cloneable, returns a clone.

source

pub const fn try_static_ascii(&self) -> Option<&'static [u8]>

source

pub fn as_bytes(&self) -> &[u8]

source

pub fn as_str(&self) -> &str

source

pub fn v8<'a>(&self, scope: &mut HandleScope<'a>) -> Local<'a, String>

Create a v8 string from this FastString. If the string is static and contains only ASCII characters, an external one-byte static is created.

source

pub fn truncate(&mut self, index: usize)

Truncates a FastString value, possibly re-allocating or memcpy’ing. May be slow.

Trait Implementations§

source§

impl AsRef<str> for FastString

source§

fn as_ref(&self) -> &str

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

impl Borrow<str> for FastString

source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
source§

impl Debug for FastString

source§

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

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

impl Default for FastString

source§

fn default() -> Self

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

impl From<Arc<str>> for FastString

FastString can be made cheaply from Arc<str> as we know it’s shared and don’t need to do an ASCII check.

source§

fn from(value: Arc<str>) -> Self

Converts to this type from the input type.
source§

impl From<String> for FastString

FastString can be made cheaply from String as we know it’s owned and don’t need to do an ASCII check.

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl From<Url> for FastString

FastString can be made cheaply from Url as we know it’s owned and don’t need to do an ASCII check.

source§

fn from(value: Url) -> Self

Converts to this type from the input type.
source§

impl Hash for FastString

source§

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

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 PartialEq for FastString

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for FastString

Auto Trait Implementations§

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
§

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

§

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

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

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

§

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, 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, U> TryFrom<U> for T
where U: Into<T>,

§

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> TryInto<U> for T
where U: TryFrom<T>,

§

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.