use std::rc::Rc;
use super::ContextInner;
use crate::assets::loadable::sprite::Sprite;
pub trait LoadMethod {
#[allow(private_interfaces)]
fn sprite(&self, ctx: &mut ContextInner) -> Rc<Sprite>;
}
pub struct ByPath<'path>(&'path str);
impl<'path> ByPath<'path> {
#[inline]
#[must_use]
pub const fn new(path: &'path str) -> Self {
Self(path)
}
#[inline]
#[must_use]
pub const fn path(&self) -> &'path str {
self.0
}
}
impl LoadMethod for ByPath<'_> {
#[inline]
#[allow(private_interfaces)]
fn sprite(&self, ctx: &mut ContextInner) -> Rc<Sprite> {
ctx.sprite(self.0)
}
}
pub struct FromMemory(Rc<Sprite>);
impl FromMemory {
#[inline]
#[must_use]
pub(crate) fn new(sprite: Sprite) -> Self {
Self(Rc::new(sprite))
}
}
impl LoadMethod for FromMemory {
#[inline]
#[allow(private_interfaces)]
fn sprite(&self, _ctx: &mut ContextInner) -> Rc<Sprite> {
Rc::clone(&self.0)
}
}