pub enum ModuleCode {
    Static(&'static [u8]),
    Owned(Vec<u8>),
    Arc(Arc<str>),
}
Expand description

Module 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 ModuleCode created from a 'static byte array or string must contain ASCII characters.

Examples of ways to construct a ModuleCode object:


let code: ModuleCode = "a string".into();
let code: ModuleCode = b"a string".into();

Variants§

§

Static(&'static [u8])

Created from static data – must be 100% 7-bit ASCII!

§

Owned(Vec<u8>)

An owned chunk of data.

§

Arc(Arc<str>)

Scripts loaded from the deno_graph infrastructure.

Implementations§

source§

impl ModuleCode

source

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

source

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

source

pub fn take_as_string(self) -> String

Takes a ModuleCode value as an owned String. May be slow.

source

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

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

Trait Implementations§

source§

impl Debug for ModuleCode

source§

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

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

impl Default for ModuleCode

source§

fn default() -> Self

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

impl From<&'static [u8]> for ModuleCode

source§

fn from(value: &'static [u8]) -> Self

Converts to this type from the input type.
source§

impl<const N: usize> From<&'static [u8; N]> for ModuleCode

source§

fn from(value: &'static [u8; N]) -> Self

Converts to this type from the input type.
source§

impl From<&'static str> for ModuleCode

source§

fn from(value: &'static str) -> Self

Converts to this type from the input type.
source§

impl From<&Arc<str>> for ModuleCode

source§

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

Converts to this type from the input type.
source§

impl From<Arc<str>> for ModuleCode

source§

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

Converts to this type from the input type.
source§

impl From<Cow<'static, [u8]>> for ModuleCode

source§

fn from(value: Cow<'static, [u8]>) -> Self

Converts to this type from the input type.
source§

impl From<Cow<'static, str>> for ModuleCode

source§

fn from(value: Cow<'static, str>) -> Self

Converts to this type from the input type.
source§

impl From<String> for ModuleCode

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl From<Vec<u8, Global>> for ModuleCode

source§

fn from(value: Vec<u8>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.