// Image + ImageSet + ResolutionLevel. Mirrors NPE Image.java. // // HEIGHT_UNKNOWN / WIDTH_UNKNOWN are -1 sentinels — kept as i32, not // Option, because several JSON output sites encode this directly. pub const HEIGHT_UNKNOWN: i32 = -1; pub const WIDTH_UNKNOWN: i32 = -1; #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub enum ResolutionLevel { Low, Medium, High, Unknown, } impl ResolutionLevel { pub fn from_height(height: i32) -> Self { if height == HEIGHT_UNKNOWN { ResolutionLevel::Unknown } else if height <= 175 { ResolutionLevel::Low } else if height <= 720 { ResolutionLevel::Medium } else { ResolutionLevel::High } } } #[derive(Clone, Debug)] pub struct Image { url: String, height: i32, width: i32, estimated_resolution_level: ResolutionLevel, } impl Image { pub fn new( url: impl Into, height: i32, width: i32, estimated_resolution_level: ResolutionLevel, ) -> Self { Self { url: url.into(), height, width, estimated_resolution_level, } } pub fn url(&self) -> &str { &self.url } pub fn height(&self) -> i32 { self.height } pub fn width(&self) -> i32 { self.width } pub fn estimated_resolution_level(&self) -> ResolutionLevel { self.estimated_resolution_level } } pub type ImageSet = Vec;