use bevy_asset::{Asset, Handle};
use bevy_reflect::Reflect;
#[derive(Clone, Debug, Reflect)]
pub enum HandleOrPath<T: Asset> {
Handle(Handle<T>),
Path(String),
}
impl<T: Asset> Default for HandleOrPath<T> {
fn default() -> Self {
Self::Path("".to_string())
}
}
impl<T: Asset> PartialEq for HandleOrPath<T> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(HandleOrPath::Handle(h1), HandleOrPath::Handle(h2)) => h1 == h2,
(HandleOrPath::Path(p1), HandleOrPath::Path(p2)) => p1 == p2,
_ => false,
}
}
}
impl<T: Asset> From<Handle<T>> for HandleOrPath<T> {
fn from(h: Handle<T>) -> Self {
HandleOrPath::Handle(h)
}
}
impl<T: Asset> From<&str> for HandleOrPath<T> {
fn from(p: &str) -> Self {
HandleOrPath::Path(p.to_string())
}
}
impl<T: Asset> From<String> for HandleOrPath<T> {
fn from(p: String) -> Self {
HandleOrPath::Path(p.clone())
}
}
impl<T: Asset> From<&String> for HandleOrPath<T> {
fn from(p: &String) -> Self {
HandleOrPath::Path(p.to_string())
}
}
impl<T: Asset + Clone> From<&HandleOrPath<T>> for HandleOrPath<T> {
fn from(p: &HandleOrPath<T>) -> Self {
p.to_owned()
}
}