Skip to content

Commit

Permalink
AnnotatedValue impl split into several files
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Mar 27, 2024
1 parent 0b229c2 commit dc9c49b
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 196 deletions.
200 changes: 4 additions & 196 deletions framework/base/src/types/interaction/annotated.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -31,199 +35,3 @@ where
f(&self.to_value(env))
}
}

impl<Env> AnnotatedValue<Env, ManagedAddress<Env::Api>> for ManagedAddress<Env::Api>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.hex_expr()
}

fn to_value(&self, env: &Env) -> ManagedAddress<Env::Api> {
self.clone()
}

fn into_value(self, _env: &Env) -> ManagedAddress<Env::Api> {
self
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&ManagedAddress<Env::Api>) -> R,
{
f(self)
}
}

impl<Env> AnnotatedValue<Env, ManagedAddress<Env::Api>> for &ManagedAddress<Env::Api>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.hex_expr()
}

fn to_value(&self, env: &Env) -> ManagedAddress<Env::Api> {
(*self).clone()
}

fn into_value(self, _env: &Env) -> ManagedAddress<Env::Api> {
self.clone()
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&ManagedAddress<Env::Api>) -> R,
{
f(self)
}
}

impl<Env> AnnotatedValue<Env, ManagedAddress<Env::Api>> for Address
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
ManagedAddress::from(self).hex_expr()
}

fn to_value(&self, env: &Env) -> ManagedAddress<Env::Api> {
ManagedAddress::from(self)
}
}

impl<Env> AnnotatedValue<Env, ManagedAddress<Env::Api>> for &Address
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
ManagedAddress::from(*self).hex_expr()
}

fn to_value(&self, env: &Env) -> ManagedAddress<Env::Api> {
ManagedAddress::from(*self)
}
}

impl<Env> AnnotatedValue<Env, ManagedBuffer<Env::Api>> for ManagedBuffer<Env::Api>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.hex_expr()
}

fn to_value(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.clone()
}

fn into_value(self, _env: &Env) -> ManagedBuffer<Env::Api> {
self
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&ManagedBuffer<Env::Api>) -> R,
{
f(self)
}
}

impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for BigUint<Env::Api>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.to_display()
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
self.clone()
}

fn into_value(self, _env: &Env) -> BigUint<Env::Api> {
self
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&BigUint<Env::Api>) -> R,
{
f(self)
}
}

impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for &BigUint<Env::Api>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.to_display()
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
(*self).clone()
}

fn into_value(self, _env: &Env) -> BigUint<Env::Api> {
self.clone()
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&BigUint<Env::Api>) -> R,
{
f(self)
}
}

impl<'a, Env> AnnotatedValue<Env, BigUint<Env::Api>> for ManagedRef<'a, Env::Api, BigUint<Env::Api>>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.to_display()
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
(*self).clone_value()
}

fn into_value(self, _env: &Env) -> BigUint<Env::Api> {
self.clone_value()
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&BigUint<Env::Api>) -> R,
{
f(self)
}
}

impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for u64
where
Env: TxEnv,
{
fn annotation(&self, env: &Env) -> ManagedBuffer<Env::Api> {
self.to_value(env).to_display()
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
BigUint::from(*self)
}
}

impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for ()
where
Env: TxEnv,
{
fn annotation(&self, env: &Env) -> ManagedBuffer<Env::Api> {
ManagedBuffer::from("0")
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
BigUint::zero()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use crate::{
proxy_imports::ManagedRef,
types::{heap::Address, BigUint, ManagedAddress, ManagedBuffer},
};

use super::{AnnotatedValue, TxEnv};

impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for BigUint<Env::Api>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.to_display()
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
self.clone()
}

fn into_value(self, _env: &Env) -> BigUint<Env::Api> {
self
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&BigUint<Env::Api>) -> R,
{
f(self)
}
}

impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for &BigUint<Env::Api>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.to_display()
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
(*self).clone()
}

fn into_value(self, _env: &Env) -> BigUint<Env::Api> {
self.clone()
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&BigUint<Env::Api>) -> R,
{
f(self)
}
}

impl<'a, Env> AnnotatedValue<Env, BigUint<Env::Api>> for ManagedRef<'a, Env::Api, BigUint<Env::Api>>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.to_display()
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
(*self).clone_value()
}

fn into_value(self, _env: &Env) -> BigUint<Env::Api> {
self.clone_value()
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&BigUint<Env::Api>) -> R,
{
f(self)
}
}

impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for u64
where
Env: TxEnv,
{
fn annotation(&self, env: &Env) -> ManagedBuffer<Env::Api> {
self.to_value(env).to_display()
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
BigUint::from(*self)
}
}

impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for ()
where
Env: TxEnv,
{
fn annotation(&self, env: &Env) -> ManagedBuffer<Env::Api> {
ManagedBuffer::from("0")
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
BigUint::zero()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use crate::{
proxy_imports::ManagedRef,
types::{heap::Address, BigUint, ManagedAddress, ManagedBuffer},
};

use super::{AnnotatedValue, TxEnv};

impl<Env> AnnotatedValue<Env, ManagedAddress<Env::Api>> for ManagedAddress<Env::Api>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.hex_expr()
}

fn to_value(&self, env: &Env) -> ManagedAddress<Env::Api> {
self.clone()
}

fn into_value(self, _env: &Env) -> ManagedAddress<Env::Api> {
self
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&ManagedAddress<Env::Api>) -> R,
{
f(self)
}
}

impl<Env> AnnotatedValue<Env, ManagedAddress<Env::Api>> for &ManagedAddress<Env::Api>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.hex_expr()
}

fn to_value(&self, env: &Env) -> ManagedAddress<Env::Api> {
(*self).clone()
}

fn into_value(self, _env: &Env) -> ManagedAddress<Env::Api> {
self.clone()
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&ManagedAddress<Env::Api>) -> R,
{
f(self)
}
}

impl<Env> AnnotatedValue<Env, ManagedAddress<Env::Api>> for Address
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
ManagedAddress::from(self).hex_expr()
}

fn to_value(&self, env: &Env) -> ManagedAddress<Env::Api> {
ManagedAddress::from(self)
}
}

impl<Env> AnnotatedValue<Env, ManagedAddress<Env::Api>> for &Address
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
ManagedAddress::from(*self).hex_expr()
}

fn to_value(&self, env: &Env) -> ManagedAddress<Env::Api> {
ManagedAddress::from(*self)
}
}
Loading

0 comments on commit dc9c49b

Please sign in to comment.