include_js_core

Struct JSStr

Source
pub struct JSStr { /* private fields */ }
Expand description

Wrapper around str that ensures it contains syntactically valid Javascript. This is the borrowed version of JSString so &JSStr is to JSString what &str is to String

Implementations§

Source§

impl JSStr

Source

pub fn new(js: &str) -> Result<&Self, JSParseError>

Checks if the content of js is syntactically valid Javascript before coersing it to &JSStr

§Examples
use include_js::JSStr;
 
let js_str = JSStr::new("function f() {}");
assert!(js_str.is_ok());
use include_js::JSStr;

let js_str = JSStr::new("#include <vector>");
assert!(js_str.is_err());
Source

pub const unsafe fn new_unchecked(js: &str) -> &Self

Coerses js directly into a &JSStr without checking for validity

Source

pub fn as_str(&self) -> &str

Converts the &JSStr back into an &str, this should be a noop.

Trait Implementations§

Source§

impl AsRef<JSStr> for JSStr

Source§

fn as_ref(&self) -> &JSStr

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

impl AsRef<JSStr> for JSString

Source§

fn as_ref(&self) -> &JSStr

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

impl AsRef<str> for JSStr

Source§

fn as_ref(&self) -> &str

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

impl Borrow<JSStr> for JSString

Source§

fn borrow(&self) -> &JSStr

Immutably borrows from an owned value. Read more
Source§

impl<'a> Into<&'a str> for &'a JSStr

Source§

fn into(self) -> &'a str

Converts this type into the (usually inferred) input type.
Source§

impl ToOwned for JSStr

Source§

type Owned = JSString

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

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

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<'a> TryFrom<&'a str> for &'a JSStr

Source§

type Error = ParseError

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

fn try_from(value: &'a str) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for JSStr

§

impl RefUnwindSafe for JSStr

§

impl Send for JSStr

§

impl !Sized for JSStr

§

impl Sync for JSStr

§

impl Unpin for JSStr

§

impl UnwindSafe for JSStr

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