Skip to main content

openusd_rs/
tf.rs

1//! Tools Foundations
2
3/// Token for efficient comparison, assignment, and hashing of known strings.
4#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
5pub struct Token {
6	data: String,
7}
8
9impl Token {
10	pub fn new(name: impl ToString) -> Self {
11		Token {
12			data: name.to_string(),
13		}
14	}
15
16	pub fn is_empty(&self) -> bool {
17		self.data.is_empty()
18	}
19
20	pub fn as_str(&self) -> &str {
21		&self.data
22	}
23}
24
25impl std::fmt::Display for Token {
26	fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
27		write!(f, "{}", self.data)
28	}
29}
30
31macro_rules! declare_public_tokens {
32	($struct:ident, $static:ident, [$($name:ident: $value:expr),*]) => {
33		pub struct $struct {
34			$(pub $name: tf::Token,)*
35		}
36
37		pub static $static: std::sync::LazyLock<$struct> = std::sync::LazyLock::new(|| {
38			$struct {
39				$($name: tf::Token::new($value),)*
40			}
41		});
42	};
43}
44
45pub(crate) use declare_public_tokens;