Validate cross-field constraints before applying emulation.
(&self)
| 25 | impl EmulateParams { |
| 26 | /// Validate cross-field constraints before applying emulation. |
| 27 | pub fn validate(&self) -> Result<()> { |
| 28 | if let Some(dsf) = self.device_scale_factor { |
| 29 | if !dsf.is_finite() || dsf <= 0.0 { |
| 30 | anyhow::bail!("device-scale-factor must be a positive finite value"); |
| 31 | } |
| 32 | } |
| 33 | if let Some(acc) = self.accuracy { |
| 34 | if acc.is_sign_negative() || !acc.is_finite() { |
| 35 | anyhow::bail!("accuracy must be a non-negative finite value"); |
| 36 | } |
| 37 | } |
| 38 | if self.accuracy.is_some() && self.geolocation.is_none() { |
| 39 | anyhow::bail!("--accuracy requires --geolocation"); |
| 40 | } |
| 41 | if self.mobile && self.viewport.is_none() { |
| 42 | anyhow::bail!("--mobile requires --viewport"); |
| 43 | } |
| 44 | if self.device_scale_factor.is_some() && self.viewport.is_none() { |
| 45 | anyhow::bail!("--device-scale-factor requires --viewport"); |
| 46 | } |
| 47 | Ok(()) |
| 48 | } |
| 49 | |
| 50 | /// Returns true if any flag that triggers emulation is set. |
| 51 | pub fn has_emulation(&self) -> bool { |
no outgoing calls
no test coverage detected