openusd_rs/usd/
attribute.rs1use super::Property;
2use crate::{
3 sdf, tf, usd,
4 vt::{self, ValueType},
5};
6
7#[repr(transparent)]
9pub struct Attribute<'a>(Property<'a>);
10
11impl<'a> Attribute<'a> {
12 pub(crate) fn new(stage: &'a usd::Stage, path: sdf::Path) -> Self {
13 Attribute(Property::new(stage, path))
14 }
15
16 #[track_caller]
17 pub fn get<T: ValueType>(&self) -> T {
18 self.stage()
19 .data()
20 .get(&self.path(), &sdf::FIELD_KEYS.default)
21 .unwrap()
22 .get::<T>()
23 .unwrap()
24 }
25
26 pub fn get_value(&self) -> Option<vt::Value> {
27 self.stage()
28 .data()
29 .get(&self.path(), &sdf::FIELD_KEYS.default)
30 }
31
32 pub fn type_name(&self) -> tf::Token {
33 self.metadata(&sdf::FIELD_KEYS.type_name)
34 .unwrap_or_default()
35 }
36}
37
38impl<'a> std::ops::Deref for Attribute<'a> {
39 type Target = Property<'a>;
40 fn deref(&self) -> &Self::Target {
41 unsafe { std::mem::transmute(self) }
42 }
43}