leo_ast/types/
future.rs

1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use crate::{Location, Type};
18
19use serde::{Deserialize, Serialize};
20use std::fmt;
21
22/// A future type consisting of the type of the inputs.
23#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
24pub struct FutureType {
25    // Optional type specification of inputs.
26    pub inputs: Vec<Type>,
27    // The location of the function that produced the future.
28    pub location: Option<Location>,
29    // Whether or not the type has been explicitly specified.
30    pub is_explicit: bool,
31}
32
33impl FutureType {
34    /// Initialize a new future type.
35    pub fn new(inputs: Vec<Type>, location: Option<Location>, is_explicit: bool) -> Self {
36        Self { inputs, location, is_explicit }
37    }
38
39    /// Returns the inputs of the future type.
40    pub fn inputs(&self) -> &[Type] {
41        &self.inputs
42    }
43
44    /// Returns the location of the future type.
45    pub fn location(&self) -> &Option<Location> {
46        &self.location
47    }
48}
49
50impl Default for crate::FutureType {
51    fn default() -> Self {
52        Self::new(vec![], None, false)
53    }
54}
55
56impl fmt::Display for crate::FutureType {
57    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58        write!(f, "Future<Fn({})>", self.inputs.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(","))
59    }
60}