leo_ast/types/future.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
// Copyright (C) 2019-2025 Provable 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::{Location, Type};
use serde::{Deserialize, Serialize};
use std::fmt;
/// A future type consisting of the type of the inputs.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct FutureType {
// Optional type specification of inputs.
pub inputs: Vec<Type>,
// The location of the function that produced the future.
pub location: Option<Location>,
// Whether or not the type has been explicitly specified.
pub is_explicit: bool,
}
impl FutureType {
/// Initialize a new future type.
pub fn new(inputs: Vec<Type>, location: Option<Location>, is_explicit: bool) -> Self {
Self { inputs, location, is_explicit }
}
/// Returns the inputs of the future type.
pub fn inputs(&self) -> &[Type] {
&self.inputs
}
/// Returns the location of the future type.
pub fn location(&self) -> &Option<Location> {
&self.location
}
}
impl Default for crate::FutureType {
fn default() -> Self {
Self::new(vec![], None, false)
}
}
impl fmt::Display for crate::FutureType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Future<Fn({})>", self.inputs.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(","))
}
}