use crate::alloc::{
string::{
String,
ToString,
},
vec::Vec,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ConstUrlResource {
pub urls: &'static [&'static str],
pub hash: Option<&'static str>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UrlResource {
pub urls: Vec<String>,
pub hash: Option<String>,
}
impl From<ConstUrlResource> for UrlResource {
fn from(resource: ConstUrlResource) -> Self {
UrlResource {
urls: resource.urls.iter().map(|s| s.to_string()).collect(),
hash: resource.hash.map(|s| s.to_string()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ConstKeyedResource {
pub key: &'static [&'static str],
pub resource: ConstUrlResource,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct KeyedResource {
pub key: Vec<String>,
pub resource: UrlResource,
}
impl From<ConstKeyedResource> for KeyedResource {
fn from(resource: ConstKeyedResource) -> Self {
KeyedResource {
key: resource.key.iter().map(|s| s.to_string()).collect(),
resource: resource.resource.into(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::alloc::{
string::ToString,
vec,
};
#[test]
fn test_keyed_resource() {
let cres = ConstKeyedResource {
key: &["test_key"],
resource: ConstUrlResource {
urls: &["test_url"],
hash: Some("test_hash"),
},
};
let res: KeyedResource = cres.into();
assert_eq!(res.key, vec!["test_key".to_string()]);
assert_eq!(res.resource.urls, vec!["test_url".to_string()]);
assert_eq!(res.resource.hash, Some("test_hash".to_string()));
}
}