Struct boa_parser::source::Source

source ·
pub struct Source<'path, R> { /* private fields */ }
Expand description

A source of ECMAScript code.

Sources can be created from plain strs, file Paths or more generally, any Read instance.

Implementations§

source§

impl<'bytes> Source<'static, UTF8Input<&'bytes [u8]>>

source

pub fn from_bytes<T: AsRef<[u8]> + ?Sized>(source: &'bytes T) -> Self

Creates a new Source from any type equivalent to a slice of bytes e.g. &str, Vec<u8>, Box<[u8]> or a plain slice &[u8].

§Examples
let code = r#"var array = [5, 4, 3, 2, 1];"#;
let source = Source::from_bytes(code);
source§

impl<'input> Source<'static, UTF16Input<'input>>

source

pub fn from_utf16(input: &'input [u16]) -> Self

Creates a new Source from a UTF-16 encoded slice e.g. &[u16].

§Examples
let utf16: Vec<u16> = "var array = [5, 4, 3, 2, 1];".encode_utf16().collect();
let source = Source::from_utf16(&utf16);
source§

impl<'path> Source<'path, UTF8Input<BufReader<File>>>

source

pub fn from_filepath(source: &'path Path) -> Result<Self>

Creates a new Source from a Path to a file.

§Errors

See File::open.

§Examples
let path = Path::new("script.js");
let source = Source::from_filepath(path)?;
source§

impl<'path, R: Read> Source<'path, UTF8Input<R>>

source

pub fn from_reader(reader: R, path: Option<&'path Path>) -> Self

Creates a new Source from a Read instance and an optional Path.

§Examples
let strictler = r#""use strict""#;

let path = Path::new("no_strict.js");
let file = File::open(path)?;
let strict = strictler.as_bytes().chain(file);

let source = Source::from_reader(strict, Some(path));

Trait Implementations§

source§

impl<'path, R: Debug> Debug for Source<'path, R>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'path, R> RefUnwindSafe for Source<'path, R>
where R: RefUnwindSafe,

§

impl<'path, R> Send for Source<'path, R>
where R: Send,

§

impl<'path, R> Sync for Source<'path, R>
where R: Sync,

§

impl<'path, R> Unpin for Source<'path, R>
where R: Unpin,

§

impl<'path, R> UnwindSafe for Source<'path, R>
where R: UnwindSafe,

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<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.
source§

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

source§

impl<T> MaybeSendSync for T