pub struct Texture(pub String);Expand description
The value of a texture variable in the Textures map.
The string value will either specify a location to load the texture from
or a reference to another texture variable to take its value from.
Tuple Fields§
§0: StringImplementations§
Source§impl Texture
impl Texture
Sourcepub fn location(&self) -> Option<&str>
pub fn location(&self) -> Option<&str>
Returns the resource location of the texture, or None if the texture
should instead take on the value of another texture variable.
§Example
let texture = Texture::from("texture/location");
assert_eq!(texture.location(), Some("texture/location"));
let texture = Texture::from("#another_var");
assert_eq!(texture.location(), None);Sourcepub fn reference(&self) -> Option<&str>
pub fn reference(&self) -> Option<&str>
Returns the name of the texture variable from which this texture should
get its value, or None if the texture should be loaded from a
resource.
§Example
let texture = Texture::from("texture/location");
assert_eq!(texture.reference(), None);
let texture = Texture::from("#another_var");
assert_eq!(texture.reference(), Some("another_var"));Sourcepub fn resolve<'a>(&'a self, substitutions: &'a Textures) -> Option<&'a str>
pub fn resolve<'a>(&'a self, substitutions: &'a Textures) -> Option<&'a str>
Resolves this texture value using the variables present in other, or
returns None if:
- This texture value not reference another texture variable, or
- There is no variable in
otherthat matches
§Example
use maplit::hashmap;
let substitutions = Textures::from(hashmap! {
"foo" => "textures/foo",
"bar" => "#another_var",
});
let texture = Texture::from("#foo");
assert_eq!(texture.resolve(&substitutions), Some("textures/foo"));
let texture = Texture::from("#bar");
assert_eq!(texture.resolve(&substitutions), Some("#another_var"));
let texture = Texture::from("#not_found");
assert_eq!(texture.resolve(&substitutions), None);
let texture = Texture::from("not_a_reference");
assert_eq!(texture.resolve(&substitutions), None);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Texture
impl<'de> Deserialize<'de> for Texture
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Texture
impl StructuralPartialEq for Texture
Auto Trait Implementations§
impl Freeze for Texture
impl RefUnwindSafe for Texture
impl Send for Texture
impl Sync for Texture
impl Unpin for Texture
impl UnwindSafe for Texture
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more