Skip to main content

ViewerHandle

Struct ViewerHandle 

Source
pub struct ViewerHandle {
    pub id: Uuid,
    /* private fields */
}
Expand description

A handle to a running viewer process in non-blocking mode.

Fields§

§id: Uuid

Unique identifier for this viewer instance.

Implementations§

Source§

impl ViewerHandle

Source

pub fn try_wait(&mut self) -> Result<Option<ViewerExitStatus>, ViewerError>

Try to check whether the viewer has finished and return its exit status.

This is non-blocking. Returns Ok(None) if the process is still running.

§Example
use html_view::{ViewerOptions, ViewerWaitMode, ViewerResult};

let mut options = ViewerOptions::inline_html("<h1>Test</h1>");
options.wait = ViewerWaitMode::NonBlocking;

if let ViewerResult::NonBlocking(mut handle) = html_view::open(options).unwrap() {
    loop {
        if let Some(status) = handle.try_wait().unwrap() {
            println!("Viewer exited: {:?}", status);
            break;
        }
        // Do other work...
        std::thread::sleep(std::time::Duration::from_millis(100));
    }
}
Source

pub fn wait(self) -> Result<ViewerExitStatus, ViewerError>

Block until the viewer finishes and return its exit status.

§Example
use html_view::{ViewerOptions, ViewerWaitMode, ViewerResult};

let mut options = ViewerOptions::inline_html("<h1>Test</h1>");
options.wait = ViewerWaitMode::NonBlocking;

if let ViewerResult::NonBlocking(handle) = html_view::open(options).unwrap() {
    let status = handle.wait().unwrap();
    println!("Viewer exited: {:?}", status);
}
Source

pub fn terminate(&mut self) -> Result<(), ViewerError>

Attempt to terminate the viewer process early.

§Example
use html_view::{ViewerOptions, ViewerWaitMode, ViewerResult};

let mut options = ViewerOptions::inline_html("<h1>Test</h1>");
options.wait = ViewerWaitMode::NonBlocking;

if let ViewerResult::NonBlocking(mut handle) = html_view::open(options).unwrap() {
    std::thread::sleep(std::time::Duration::from_secs(2));
    handle.terminate().unwrap();
}
Source

pub fn refresh(&mut self, content: ViewerContent) -> Result<(), ViewerError>

Refresh the viewer with new content.

This updates the displayed content without closing the window. The window and behavior options remain unchanged.

§Example
use html_view::{ViewerOptions, ViewerWaitMode, ViewerResult, ViewerContent};

let mut options = ViewerOptions::inline_html("<h1>Initial</h1>");
options.wait = ViewerWaitMode::NonBlocking;

if let ViewerResult::NonBlocking(mut handle) = html_view::open(options).unwrap() {
    std::thread::sleep(std::time::Duration::from_secs(2));

    // Update content
    handle.refresh(ViewerContent::InlineHtml {
        html: "<h1>Updated!</h1>".to_string(),
        base_dir: None,
    }).unwrap();
}
Source

pub fn refresh_html<S: Into<String>>( &mut self, html: S, ) -> Result<(), ViewerError>

Refresh the viewer with inline HTML (convenience method).

§Example
use html_view::{ViewerOptions, ViewerWaitMode, ViewerResult};

let mut options = ViewerOptions::inline_html("<h1>Initial</h1>");
options.wait = ViewerWaitMode::NonBlocking;

if let ViewerResult::NonBlocking(mut handle) = html_view::open(options).unwrap() {
    std::thread::sleep(std::time::Duration::from_secs(2));
    handle.refresh_html("<h1>Updated!</h1>").unwrap();
}

Trait Implementations§

Source§

impl Debug for ViewerHandle

Source§

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

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

impl Drop for ViewerHandle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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>,

Source§

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>,

Source§

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.