mod key;
use key::*;
mod value;
use value::*;
mod bytes;
mod parse;
use console::{network::prelude::*, program::Identifier};
#[derive(Clone, PartialEq, Eq)]
pub struct Mapping<N: Network> {
name: Identifier<N>,
key: MapKey<N>,
value: MapValue<N>,
}
impl<N: Network> Mapping<N> {
pub fn new(name: Identifier<N>, key: MapKey<N>, value: MapValue<N>) -> Self {
Self { name, key, value }
}
pub const fn name(&self) -> &Identifier<N> {
&self.name
}
pub const fn key(&self) -> &MapKey<N> {
&self.key
}
pub const fn value(&self) -> &MapValue<N> {
&self.value
}
pub fn contains_external_struct(&self) -> bool {
self.key.plaintext_type().contains_external_struct() || self.value.plaintext_type().contains_external_struct()
}
pub fn contains_string_type(&self) -> bool {
self.key.plaintext_type().contains_string_type() || self.value.plaintext_type().contains_string_type()
}
pub fn contains_identifier_type(&self) -> Result<bool> {
Ok(self.key.plaintext_type().contains_identifier_type()?
|| self.value.plaintext_type().contains_identifier_type()?)
}
pub fn exceeds_max_array_size(&self, max_array_size: u32) -> bool {
self.key.plaintext_type().exceeds_max_array_size(max_array_size)
|| self.value.plaintext_type().exceeds_max_array_size(max_array_size)
}
}
impl<N: Network> TypeName for Mapping<N> {
#[inline]
fn type_name() -> &'static str {
"mapping"
}
}