use semver::Version;
use serde_json::Value;
pub struct Lens {
pub product_group: String,
pub from: Version,
pub to: Version,
pub lossy: bool,
pub note: &'static str,
pub(super) transform: fn(&Value) -> Result<Value, LensError>,
}
impl Lens {
#[must_use]
pub fn new(
product_group: impl Into<String>,
from: Version,
to: Version,
lossy: bool,
note: &'static str,
transform: fn(&Value) -> Result<Value, LensError>,
) -> Self {
Self {
product_group: product_group.into(),
from,
to,
lossy,
note,
transform,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LensError(pub String);
impl std::fmt::Display for LensError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "lens transform failed: {}", self.0)
}
}