pub struct Found {
pub name: String,
pub span: Span,
pub value: Result<Json, Refused>,
}Expand description
A piece of page state: where a script put it, and its value, or why it isn’t data.
Fields§
§name: StringWhat the script assigned: window.__NUXT__, window.__NUXT__.config,
ytInitialData for a top-level var, self.__next_f for each of
Next.js’s pushes. A key that isn’t a name is written as a JSON
string in brackets, window["a-b"].
span: SpanThe value’s expression in the source.
value: Result<Json, Refused>Implementations§
Source§impl Found
impl Found
Sourcepub fn write_json(&self, src: &str, out: &mut String)
pub fn write_json(&self, src: &str, out: &mut String)
The piece as a JSON object, for a binding or a tool that hands
JSON on: {"name": …, "value": …}, or for a value that isn’t data
{"name": …, "error": {"code": …, "source": …}}, where code is
the Refused reason and source the start of the text that
stopped it, at most 80 characters with … after a cut. src is
the script the piece was found in.
use parsec_js::data::page_state;
let src = "window.a = {b: 1}; window.c = f();";
let found = page_state(src).unwrap();
let mut out = String::new();
found[0].write_json(src, &mut out);
found[1].write_json(src, &mut out);
assert_eq!(
out,
r#"{"name":"window.a","value":{"b":1}}{"name":"window.c","error":{"code":"not-a-literal","source":"f()"}}"#
);Trait Implementations§
impl StructuralPartialEq for Found
Auto Trait Implementations§
impl Forget for Found
impl Freeze for Found
impl Move for Found
impl RefUnwindSafe for Found
impl Send for Found
impl Sync for Found
impl Unpin for Found
impl UnsafeUnpin for Found
impl UnwindSafe for Found
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
Mutably borrows from an owned value. Read more