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
impl JSStr
Sourcepub fn new(js: &str) -> Result<&Self, JSParseError>
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());
Sourcepub const unsafe fn new_unchecked(js: &str) -> &Self
pub const unsafe fn new_unchecked(js: &str) -> &Self
Coerses js
directly into a &JSStr
without checking for validity