32 lines
724 B
Rust
32 lines
724 B
Rust
use std::sync::Arc;
|
|
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
|
pub enum ResourceState {
|
|
Loading,
|
|
Ready,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct Resource<T> {
|
|
pub path: String,
|
|
pub data: Option<Arc<T>>,
|
|
pub uuid: Uuid,
|
|
pub state: ResourceState,
|
|
}
|
|
|
|
/// A helper type to make it easier to use resources
|
|
pub type ResHandle<T> = Arc<Resource<T>>;
|
|
|
|
impl<T> Resource<T> {
|
|
/// Create the resource with data, its assumed the state is `Ready`
|
|
pub fn with_data(path: &str, data: T) -> Self {
|
|
Self {
|
|
path: path.to_string(),
|
|
data: Some(Arc::new(data)),
|
|
uuid: Uuid::new_v4(),
|
|
state: ResourceState::Ready,
|
|
}
|
|
}
|
|
} |