pub struct ViewerHandle {
pub id: Uuid,
/* private fields */
}Expand description
A handle to a running viewer process in non-blocking mode.
Fields§
§id: UuidUnique identifier for this viewer instance.
Implementations§
Source§impl ViewerHandle
impl ViewerHandle
Sourcepub fn try_wait(&mut self) -> Result<Option<ViewerExitStatus>, ViewerError>
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));
}
}Sourcepub fn wait(self) -> Result<ViewerExitStatus, ViewerError>
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);
}Sourcepub fn terminate(&mut self) -> Result<(), ViewerError>
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();
}Sourcepub fn refresh(&mut self, content: ViewerContent) -> Result<(), ViewerError>
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();
}Sourcepub fn refresh_html<S: Into<String>>(
&mut self,
html: S,
) -> Result<(), ViewerError>
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
impl Debug for ViewerHandle
Auto Trait Implementations§
impl Freeze for ViewerHandle
impl RefUnwindSafe for ViewerHandle
impl Send for ViewerHandle
impl Sync for ViewerHandle
impl Unpin for ViewerHandle
impl UnsafeUnpin for ViewerHandle
impl UnwindSafe for ViewerHandle
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