aboutsummaryrefslogtreecommitdiff
path: root/syn/codegen/src/operand.rs
diff options
context:
space:
mode:
Diffstat (limited to 'syn/codegen/src/operand.rs')
-rw-r--r--syn/codegen/src/operand.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/syn/codegen/src/operand.rs b/syn/codegen/src/operand.rs
new file mode 100644
index 0000000..db3bd18
--- /dev/null
+++ b/syn/codegen/src/operand.rs
@@ -0,0 +1,38 @@
+use proc_macro2::TokenStream;
+use quote::quote;
+
+pub enum Operand {
+ Borrowed(TokenStream),
+ Owned(TokenStream),
+}
+
+pub use self::Operand::*;
+
+impl Operand {
+ pub fn tokens(&self) -> &TokenStream {
+ match self {
+ Borrowed(n) | Owned(n) => n,
+ }
+ }
+
+ pub fn ref_tokens(&self) -> TokenStream {
+ match self {
+ Borrowed(n) => n.clone(),
+ Owned(n) => quote!(&#n),
+ }
+ }
+
+ pub fn ref_mut_tokens(&self) -> TokenStream {
+ match self {
+ Borrowed(n) => n.clone(),
+ Owned(n) => quote!(&mut #n),
+ }
+ }
+
+ pub fn owned_tokens(&self) -> TokenStream {
+ match self {
+ Borrowed(n) => quote!(*#n),
+ Owned(n) => n.clone(),
+ }
+ }
+}