Introduce Array type

This commit is contained in:
Pranav Gaddamadugu 2023-10-06 21:35:41 -04:00 committed by Pranav Gaddamadugu
parent a5f164c1ed
commit 3fda5aab62
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,50 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Type;
use serde::{Deserialize, Serialize};
use std::fmt;
/// An array type.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ArrayType {
element: Box<Type>,
size: u32,
}
impl ArrayType {
/// Creates a new array type.
pub fn new(element: Type, size: u32) -> Self {
Self { element: Box::new(element), size }
}
/// Returns the element type of the array.
pub fn element(&self) -> &Type {
&self.element
}
/// Returns the size of the array.
pub fn size(&self) -> u32 {
self.size
}
}
impl fmt::Display for ArrayType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{}; {}]", self.element, self.size)
}
}

View File

@ -13,6 +13,10 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
pub mod array;
pub use array::*;
pub mod core_constant;
pub use core_constant::*;