Struct StaticExporterBuilder

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

Builder for configuring and creating a StaticExporter instance.

This builder provides an interface for configuring WebDriver settings, browser capabilities, and other options before creating a StaticExporter instance. The builder automatically handles WebDriver process management, including detection of existing sessions and automatic spawning when needed.

§Examples

// This example requires a running WebDriver (chromedriver/geckodriver) and a browser.
// It cannot be run as a doc test.
use plotly_static::StaticExporterBuilder;

let exporter = StaticExporterBuilder::default()
    .webdriver_port(4444)
    .spawn_webdriver(true)
    .offline_mode(false)
    .pdf_export_timeout(500)
    .build()
    .expect("Failed to build StaticExporter");

§Default Configuration

  • WebDriver port: 4444
  • WebDriver URL: “http://localhost”
  • Spawn webdriver: true (automatically manages WebDriver lifecycle)
  • Offline mode: false
  • PDF export timeout: 250ms
  • Browser capabilities: Default Chrome/Firefox headless options
  • Automatic WebDriver detection and connection reuse

Implementations§

Source§

impl StaticExporterBuilder

Source

pub fn webdriver_port(self, port: u32) -> Self

Sets the WebDriver port number.

§Examples
use plotly_static::StaticExporterBuilder;

let builder = StaticExporterBuilder::default()
    .webdriver_port(4444);
Source

pub fn webdriver_url(self, url: &str) -> Self

Sets the WebDriver URL.

§Examples
use plotly_static::StaticExporterBuilder;

let builder = StaticExporterBuilder::default()
    .webdriver_url("http://localhost");
Source

pub fn spawn_webdriver(self, yes: bool) -> Self

Controls whether to automatically spawn a WebDriver process.

If true, automatically spawns a WebDriver process. If false, expects an existing WebDriver server to be running.

§Examples
use plotly_static::StaticExporterBuilder;

// Auto-spawn WebDriver
let builder = StaticExporterBuilder::default()
    .spawn_webdriver(true);

// Use existing WebDriver server
let builder = StaticExporterBuilder::default()
    .spawn_webdriver(false);
Source

pub fn offline_mode(self, yes: bool) -> Self

Controls whether to use offline mode with bundled JavaScript libraries.

If true, uses bundled JavaScript libraries instead of CDN. If false, downloads libraries from CDN.

§Examples
use plotly_static::StaticExporterBuilder;

// Use bundled libraries (no internet required)
let builder = StaticExporterBuilder::default()
    .offline_mode(true);

// Use CDN libraries
let builder = StaticExporterBuilder::default()
    .offline_mode(false);
Source

pub fn pdf_export_timeout(self, timeout_ms: u32) -> Self

Sets the PDF export timeout in milliseconds.

This timeout controls how long to wait for the SVG image to load before proceeding with PDF generation. A longer timeout may be needed for complex plots or slower systems.

§Examples
use plotly_static::StaticExporterBuilder;

// Set a longer timeout for complex plots
let builder = StaticExporterBuilder::default()
    .pdf_export_timeout(500);

// Use default timeout (150ms)
let builder = StaticExporterBuilder::default()
    .pdf_export_timeout(150);
Source

pub fn webdriver_browser_caps(self, caps: Vec<String>) -> Self

Sets custom browser capabilities for the WebDriver.

§Examples
use plotly_static::StaticExporterBuilder;

let custom_caps = vec![
    "--headless".to_string(),
    "--no-sandbox".to_string(),
    "--disable-gpu".to_string(),
];

let builder = StaticExporterBuilder::default()
    .webdriver_browser_caps(custom_caps);
Source

pub fn build(&self) -> Result<StaticExporter>

Builds a StaticExporter instance with the current configuration.

This method creates a new StaticExporter instance with all the configured settings. The method manages WebDriver:

  • If spawn_webdriver is enabled, it first tries to connect to an existing WebDriver session on the specified port, and only spawns a new process if none is found
  • If spawn_webdriver is disabled, it creates a connection to an existing WebDriver without spawning

Returns a Result<StaticExporter> where:

  • Ok(exporter) - Successfully created the StaticExporter instance
  • Err(e) - Failed to create the instance (e.g., WebDriver not available, port conflicts, etc.)
§Examples
use plotly_static::StaticExporterBuilder;

let exporter = StaticExporterBuilder::default()
    .webdriver_port(4444)
    .build()
    .expect("Failed to build StaticExporter");

Trait Implementations§

Source§

impl Default for StaticExporterBuilder

Source§

fn default() -> Self

Creates a new StaticExporterBuilder with default configuration.

The default configuration includes:

  • WebDriver port: 4444
  • WebDriver URL: “http://localhost”
  • Spawn webdriver: true
  • Offline mode: false
  • PDF export timeout: 250ms
  • Default browser capabilities for headless operation

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T