diff --git a/framework/base/src/types/interaction/annotated.rs b/framework/base/src/types/interaction/annotated.rs index d6b75fc610..f3187d08ce 100644 --- a/framework/base/src/types/interaction/annotated.rs +++ b/framework/base/src/types/interaction/annotated.rs @@ -1,3 +1,7 @@ +mod annotated_impl_big_uint; +mod annotated_impl_managed_address; +mod annotated_impl_managed_buffer; + use crate::{ proxy_imports::ManagedRef, types::{heap::Address, BigUint, ManagedAddress, ManagedBuffer}, @@ -31,199 +35,3 @@ where f(&self.to_value(env)) } } - -impl AnnotatedValue> for ManagedAddress -where - Env: TxEnv, -{ - fn annotation(&self, _env: &Env) -> ManagedBuffer { - self.hex_expr() - } - - fn to_value(&self, env: &Env) -> ManagedAddress { - self.clone() - } - - fn into_value(self, _env: &Env) -> ManagedAddress { - self - } - - fn with_value_ref(&self, env: &Env, f: F) -> R - where - F: FnOnce(&ManagedAddress) -> R, - { - f(self) - } -} - -impl AnnotatedValue> for &ManagedAddress -where - Env: TxEnv, -{ - fn annotation(&self, _env: &Env) -> ManagedBuffer { - self.hex_expr() - } - - fn to_value(&self, env: &Env) -> ManagedAddress { - (*self).clone() - } - - fn into_value(self, _env: &Env) -> ManagedAddress { - self.clone() - } - - fn with_value_ref(&self, env: &Env, f: F) -> R - where - F: FnOnce(&ManagedAddress) -> R, - { - f(self) - } -} - -impl AnnotatedValue> for Address -where - Env: TxEnv, -{ - fn annotation(&self, _env: &Env) -> ManagedBuffer { - ManagedAddress::from(self).hex_expr() - } - - fn to_value(&self, env: &Env) -> ManagedAddress { - ManagedAddress::from(self) - } -} - -impl AnnotatedValue> for &Address -where - Env: TxEnv, -{ - fn annotation(&self, _env: &Env) -> ManagedBuffer { - ManagedAddress::from(*self).hex_expr() - } - - fn to_value(&self, env: &Env) -> ManagedAddress { - ManagedAddress::from(*self) - } -} - -impl AnnotatedValue> for ManagedBuffer -where - Env: TxEnv, -{ - fn annotation(&self, _env: &Env) -> ManagedBuffer { - self.hex_expr() - } - - fn to_value(&self, _env: &Env) -> ManagedBuffer { - self.clone() - } - - fn into_value(self, _env: &Env) -> ManagedBuffer { - self - } - - fn with_value_ref(&self, env: &Env, f: F) -> R - where - F: FnOnce(&ManagedBuffer) -> R, - { - f(self) - } -} - -impl AnnotatedValue> for BigUint -where - Env: TxEnv, -{ - fn annotation(&self, _env: &Env) -> ManagedBuffer { - self.to_display() - } - - fn to_value(&self, _env: &Env) -> BigUint { - self.clone() - } - - fn into_value(self, _env: &Env) -> BigUint { - self - } - - fn with_value_ref(&self, env: &Env, f: F) -> R - where - F: FnOnce(&BigUint) -> R, - { - f(self) - } -} - -impl AnnotatedValue> for &BigUint -where - Env: TxEnv, -{ - fn annotation(&self, _env: &Env) -> ManagedBuffer { - self.to_display() - } - - fn to_value(&self, _env: &Env) -> BigUint { - (*self).clone() - } - - fn into_value(self, _env: &Env) -> BigUint { - self.clone() - } - - fn with_value_ref(&self, env: &Env, f: F) -> R - where - F: FnOnce(&BigUint) -> R, - { - f(self) - } -} - -impl<'a, Env> AnnotatedValue> for ManagedRef<'a, Env::Api, BigUint> -where - Env: TxEnv, -{ - fn annotation(&self, _env: &Env) -> ManagedBuffer { - self.to_display() - } - - fn to_value(&self, _env: &Env) -> BigUint { - (*self).clone_value() - } - - fn into_value(self, _env: &Env) -> BigUint { - self.clone_value() - } - - fn with_value_ref(&self, env: &Env, f: F) -> R - where - F: FnOnce(&BigUint) -> R, - { - f(self) - } -} - -impl AnnotatedValue> for u64 -where - Env: TxEnv, -{ - fn annotation(&self, env: &Env) -> ManagedBuffer { - self.to_value(env).to_display() - } - - fn to_value(&self, _env: &Env) -> BigUint { - BigUint::from(*self) - } -} - -impl AnnotatedValue> for () -where - Env: TxEnv, -{ - fn annotation(&self, env: &Env) -> ManagedBuffer { - ManagedBuffer::from("0") - } - - fn to_value(&self, _env: &Env) -> BigUint { - BigUint::zero() - } -} diff --git a/framework/base/src/types/interaction/annotated/annotated_impl_big_uint.rs b/framework/base/src/types/interaction/annotated/annotated_impl_big_uint.rs new file mode 100644 index 0000000000..29f41042aa --- /dev/null +++ b/framework/base/src/types/interaction/annotated/annotated_impl_big_uint.rs @@ -0,0 +1,104 @@ +use crate::{ + proxy_imports::ManagedRef, + types::{heap::Address, BigUint, ManagedAddress, ManagedBuffer}, +}; + +use super::{AnnotatedValue, TxEnv}; + +impl AnnotatedValue> for BigUint +where + Env: TxEnv, +{ + fn annotation(&self, _env: &Env) -> ManagedBuffer { + self.to_display() + } + + fn to_value(&self, _env: &Env) -> BigUint { + self.clone() + } + + fn into_value(self, _env: &Env) -> BigUint { + self + } + + fn with_value_ref(&self, env: &Env, f: F) -> R + where + F: FnOnce(&BigUint) -> R, + { + f(self) + } +} + +impl AnnotatedValue> for &BigUint +where + Env: TxEnv, +{ + fn annotation(&self, _env: &Env) -> ManagedBuffer { + self.to_display() + } + + fn to_value(&self, _env: &Env) -> BigUint { + (*self).clone() + } + + fn into_value(self, _env: &Env) -> BigUint { + self.clone() + } + + fn with_value_ref(&self, env: &Env, f: F) -> R + where + F: FnOnce(&BigUint) -> R, + { + f(self) + } +} + +impl<'a, Env> AnnotatedValue> for ManagedRef<'a, Env::Api, BigUint> +where + Env: TxEnv, +{ + fn annotation(&self, _env: &Env) -> ManagedBuffer { + self.to_display() + } + + fn to_value(&self, _env: &Env) -> BigUint { + (*self).clone_value() + } + + fn into_value(self, _env: &Env) -> BigUint { + self.clone_value() + } + + fn with_value_ref(&self, env: &Env, f: F) -> R + where + F: FnOnce(&BigUint) -> R, + { + f(self) + } +} + +impl AnnotatedValue> for u64 +where + Env: TxEnv, +{ + fn annotation(&self, env: &Env) -> ManagedBuffer { + self.to_value(env).to_display() + } + + fn to_value(&self, _env: &Env) -> BigUint { + BigUint::from(*self) + } +} + +impl AnnotatedValue> for () +where + Env: TxEnv, +{ + fn annotation(&self, env: &Env) -> ManagedBuffer { + ManagedBuffer::from("0") + } + + fn to_value(&self, _env: &Env) -> BigUint { + BigUint::zero() + } +} diff --git a/framework/base/src/types/interaction/annotated/annotated_impl_managed_address.rs b/framework/base/src/types/interaction/annotated/annotated_impl_managed_address.rs new file mode 100644 index 0000000000..87aebbb82e --- /dev/null +++ b/framework/base/src/types/interaction/annotated/annotated_impl_managed_address.rs @@ -0,0 +1,80 @@ +use crate::{ + proxy_imports::ManagedRef, + types::{heap::Address, BigUint, ManagedAddress, ManagedBuffer}, +}; + +use super::{AnnotatedValue, TxEnv}; + +impl AnnotatedValue> for ManagedAddress +where + Env: TxEnv, +{ + fn annotation(&self, _env: &Env) -> ManagedBuffer { + self.hex_expr() + } + + fn to_value(&self, env: &Env) -> ManagedAddress { + self.clone() + } + + fn into_value(self, _env: &Env) -> ManagedAddress { + self + } + + fn with_value_ref(&self, env: &Env, f: F) -> R + where + F: FnOnce(&ManagedAddress) -> R, + { + f(self) + } +} + +impl AnnotatedValue> for &ManagedAddress +where + Env: TxEnv, +{ + fn annotation(&self, _env: &Env) -> ManagedBuffer { + self.hex_expr() + } + + fn to_value(&self, env: &Env) -> ManagedAddress { + (*self).clone() + } + + fn into_value(self, _env: &Env) -> ManagedAddress { + self.clone() + } + + fn with_value_ref(&self, env: &Env, f: F) -> R + where + F: FnOnce(&ManagedAddress) -> R, + { + f(self) + } +} + +impl AnnotatedValue> for Address +where + Env: TxEnv, +{ + fn annotation(&self, _env: &Env) -> ManagedBuffer { + ManagedAddress::from(self).hex_expr() + } + + fn to_value(&self, env: &Env) -> ManagedAddress { + ManagedAddress::from(self) + } +} + +impl AnnotatedValue> for &Address +where + Env: TxEnv, +{ + fn annotation(&self, _env: &Env) -> ManagedBuffer { + ManagedAddress::from(*self).hex_expr() + } + + fn to_value(&self, env: &Env) -> ManagedAddress { + ManagedAddress::from(*self) + } +} diff --git a/framework/base/src/types/interaction/annotated/annotated_impl_managed_buffer.rs b/framework/base/src/types/interaction/annotated/annotated_impl_managed_buffer.rs new file mode 100644 index 0000000000..bf15a3a262 --- /dev/null +++ b/framework/base/src/types/interaction/annotated/annotated_impl_managed_buffer.rs @@ -0,0 +1,30 @@ +use crate::{ + proxy_imports::ManagedRef, + types::{heap::Address, BigUint, ManagedAddress, ManagedBuffer}, +}; + +use super::{AnnotatedValue, TxEnv}; + +impl AnnotatedValue> for ManagedBuffer +where + Env: TxEnv, +{ + fn annotation(&self, _env: &Env) -> ManagedBuffer { + self.hex_expr() + } + + fn to_value(&self, _env: &Env) -> ManagedBuffer { + self.clone() + } + + fn into_value(self, _env: &Env) -> ManagedBuffer { + self + } + + fn with_value_ref(&self, env: &Env, f: F) -> R + where + F: FnOnce(&ManagedBuffer) -> R, + { + f(self) + } +}