Enum deno_core::FastString
source · 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
impl FastString
sourcepub const fn from_static(s: &'static str) -> Self
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.
sourcepub const fn ensure_static_ascii(s: &'static str) -> Self
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.
sourcepub fn into_cheap_copy(self) -> (Self, Self)
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.
pub const fn try_static_ascii(&self) -> Option<&'static [u8]>
pub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_str(&self) -> &str
sourcepub fn v8<'a>(&self, scope: &mut HandleScope<'a>) -> Local<'a, String>
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.
sourcepub fn truncate(&mut self, index: usize)
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
impl AsRef<str> for FastString
source§impl Borrow<str> for FastString
impl Borrow<str> for FastString
source§impl Debug for FastString
impl Debug for FastString
source§impl Default for FastString
impl Default for FastString
source§impl From<Arc<str>> for FastString
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§impl From<String> for FastString
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§impl From<Url> for FastString
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§impl Hash for FastString
impl Hash for FastString
source§impl PartialEq<FastString> for FastString
impl PartialEq<FastString> for FastString
impl Eq for FastString
Auto Trait Implementations§
impl RefUnwindSafe for FastString
impl Send for FastString
impl Sync for FastString
impl Unpin for FastString
impl UnwindSafe for FastString
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.