#[derive(Clone)]
enum CotisImagePath {
StringPath(String),
StaticPath(&'static str),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CotisImageError {
NotRelativePath,
EmptyPath,
}
#[derive(Clone)]
pub struct JPEGImage {
path: CotisImagePath,
}
impl JPEGImage {
pub fn new(path: &str) -> Result<Self, CotisImageError> {
if path.is_empty() {
return Err(CotisImageError::EmptyPath);
}
if path.starts_with("/") {
return Err(CotisImageError::NotRelativePath);
}
Ok(Self {
path: CotisImagePath::StringPath(path.to_string()),
})
}
pub const fn new_const(path: &'static str) -> Self {
if path.is_empty() {
panic!("CotisImageError::EmptyPath");
}
if path.as_bytes()[0] == b'/' {
panic!("CotisImageError::NotRelativePath");
}
Self {
path: CotisImagePath::StaticPath(path),
}
}
pub fn get_path(&self) -> &str {
match &self.path {
CotisImagePath::StringPath(s) => s,
CotisImagePath::StaticPath(s) => s,
}
}
}
#[derive(Clone)]
pub struct SVGImage {
path: CotisImagePath,
}
impl SVGImage {
pub fn new(path: &str) -> Result<Self, CotisImageError> {
if path.is_empty() {
return Err(CotisImageError::EmptyPath);
}
if path.starts_with("/") {
return Err(CotisImageError::NotRelativePath);
}
Ok(Self {
path: CotisImagePath::StringPath(path.to_string()),
})
}
pub const fn new_const(path: &'static str) -> Self {
if path.is_empty() {
panic!("CotisImageError::EmptyPath");
}
if path.as_bytes()[0] == b'/' {
panic!("CotisImageError::NotRelativePath");
}
Self {
path: CotisImagePath::StaticPath(path),
}
}
pub fn get_path(&self) -> &str {
match &self.path {
CotisImagePath::StringPath(s) => s,
CotisImagePath::StaticPath(s) => s,
}
}
}
#[derive(Clone)]
pub struct PNGImage {
path: CotisImagePath,
}
impl PNGImage {
pub fn new(path: &str) -> Result<Self, CotisImageError> {
if path.is_empty() {
return Err(CotisImageError::EmptyPath);
}
if path.starts_with("/") {
return Err(CotisImageError::NotRelativePath);
}
Ok(Self {
path: CotisImagePath::StringPath(path.to_string()),
})
}
pub const fn new_const(path: &'static str) -> Self {
if path.is_empty() {
panic!("CotisImageError::EmptyPath");
}
if path.as_bytes()[0] == b'/' {
panic!("CotisImageError::NotRelativePath");
}
Self {
path: CotisImagePath::StaticPath(path),
}
}
pub fn get_path(&self) -> &str {
match &self.path {
CotisImagePath::StringPath(s) => s,
CotisImagePath::StaticPath(s) => s,
}
}
}