use serde::{Serialize, Deserialize};
use serde_json::Value as JsonValue;
use std::borrow::Cow;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct ScreenshotParams<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
format: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
quality: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
optimizeForSpeed: Option<bool>,
}
impl<'a> ScreenshotParams<'a> {
pub fn builder() -> ScreenshotParamsBuilder<'a> {
ScreenshotParamsBuilder {
format: None,
quality: None,
optimizeForSpeed: None,
}
}
pub fn format(&self) -> Option<&str> { self.format.as_deref() }
pub fn quality(&self) -> Option<i64> { self.quality }
pub fn optimizeForSpeed(&self) -> Option<bool> { self.optimizeForSpeed }
}
#[derive(Default)]
pub struct ScreenshotParamsBuilder<'a> {
format: Option<Cow<'a, str>>,
quality: Option<i64>,
optimizeForSpeed: Option<bool>,
}
impl<'a> ScreenshotParamsBuilder<'a> {
pub fn format(mut self, format: impl Into<Cow<'a, str>>) -> Self { self.format = Some(format.into()); self }
pub fn quality(mut self, quality: i64) -> Self { self.quality = Some(quality); self }
pub fn optimizeForSpeed(mut self, optimizeForSpeed: bool) -> Self { self.optimizeForSpeed = Some(optimizeForSpeed); self }
pub fn build(self) -> ScreenshotParams<'a> {
ScreenshotParams {
format: self.format,
quality: self.quality,
optimizeForSpeed: self.optimizeForSpeed,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct BeginFrameParams<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
frameTimeTicks: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
interval: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
noDisplayUpdates: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
screenshot: Option<ScreenshotParams<'a>>,
}
impl<'a> BeginFrameParams<'a> {
pub fn builder() -> BeginFrameParamsBuilder<'a> {
BeginFrameParamsBuilder {
frameTimeTicks: None,
interval: None,
noDisplayUpdates: None,
screenshot: None,
}
}
pub fn frameTimeTicks(&self) -> Option<f64> { self.frameTimeTicks }
pub fn interval(&self) -> Option<f64> { self.interval }
pub fn noDisplayUpdates(&self) -> Option<bool> { self.noDisplayUpdates }
pub fn screenshot(&self) -> Option<&ScreenshotParams<'a>> { self.screenshot.as_ref() }
}
#[derive(Default)]
pub struct BeginFrameParamsBuilder<'a> {
frameTimeTicks: Option<f64>,
interval: Option<f64>,
noDisplayUpdates: Option<bool>,
screenshot: Option<ScreenshotParams<'a>>,
}
impl<'a> BeginFrameParamsBuilder<'a> {
pub fn frameTimeTicks(mut self, frameTimeTicks: f64) -> Self { self.frameTimeTicks = Some(frameTimeTicks); self }
pub fn interval(mut self, interval: f64) -> Self { self.interval = Some(interval); self }
pub fn noDisplayUpdates(mut self, noDisplayUpdates: bool) -> Self { self.noDisplayUpdates = Some(noDisplayUpdates); self }
pub fn screenshot(mut self, screenshot: ScreenshotParams<'a>) -> Self { self.screenshot = Some(screenshot); self }
pub fn build(self) -> BeginFrameParams<'a> {
BeginFrameParams {
frameTimeTicks: self.frameTimeTicks,
interval: self.interval,
noDisplayUpdates: self.noDisplayUpdates,
screenshot: self.screenshot,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct BeginFrameReturns<'a> {
hasDamage: bool,
#[serde(skip_serializing_if = "Option::is_none")]
screenshotData: Option<Cow<'a, str>>,
}
impl<'a> BeginFrameReturns<'a> {
pub fn builder(hasDamage: bool) -> BeginFrameReturnsBuilder<'a> {
BeginFrameReturnsBuilder {
hasDamage: hasDamage,
screenshotData: None,
}
}
pub fn hasDamage(&self) -> bool { self.hasDamage }
pub fn screenshotData(&self) -> Option<&str> { self.screenshotData.as_deref() }
}
pub struct BeginFrameReturnsBuilder<'a> {
hasDamage: bool,
screenshotData: Option<Cow<'a, str>>,
}
impl<'a> BeginFrameReturnsBuilder<'a> {
pub fn screenshotData(mut self, screenshotData: impl Into<Cow<'a, str>>) -> Self { self.screenshotData = Some(screenshotData.into()); self }
pub fn build(self) -> BeginFrameReturns<'a> {
BeginFrameReturns {
hasDamage: self.hasDamage,
screenshotData: self.screenshotData,
}
}
}
impl<'a> BeginFrameParams<'a> { pub const METHOD: &'static str = "HeadlessExperimental.beginFrame"; }
impl<'a> crate::CdpCommand<'a> for BeginFrameParams<'a> {
const METHOD: &'static str = "HeadlessExperimental.beginFrame";
type Response = BeginFrameReturns<'a>;
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DisableParams {}
impl DisableParams { pub const METHOD: &'static str = "HeadlessExperimental.disable"; }
impl<'a> crate::CdpCommand<'a> for DisableParams {
const METHOD: &'static str = "HeadlessExperimental.disable";
type Response = crate::EmptyReturns;
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct EnableParams {}
impl EnableParams { pub const METHOD: &'static str = "HeadlessExperimental.enable"; }
impl<'a> crate::CdpCommand<'a> for EnableParams {
const METHOD: &'static str = "HeadlessExperimental.enable";
type Response = crate::EmptyReturns;
}