leo_package/
dependency.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;
18use std::fmt::Display;
19
20use serde::{Deserialize, Serialize};
21use std::path::PathBuf;
22
23/// Information about a dependency, as represented in the `program.json` manifest.
24#[derive(Debug, Default, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
25pub struct Dependency {
26    /// The name of the program. As this corresponds to what appears in `program.json`,
27    /// it should have the ".aleo" suffix.
28    pub name: String,
29    /// Network, local, or test dependency?
30    pub location: Location,
31    /// For a local dependency, where is its package? Or, for a test, where is its source file?
32    pub path: Option<PathBuf>,
33    /// For a network dependency, what is its edition?
34    pub edition: Option<u16>,
35}
36
37impl Display for Dependency {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        write!(f, "{} (on {:?})", self.name, self.location)?;
40        if let Some(path) = &self.path {
41            write!(f, " (at {})", path.display())?;
42        }
43        if let Some(edition) = self.edition {
44            write!(f, " (edition {edition})")?;
45        }
46        Ok(())
47    }
48}