radix_common/types/
blueprint_id.rs

1use radix_common::address::{AddressDisplayContext, NO_NETWORK};
2use radix_common::types::PackageAddress;
3use radix_common::*;
4use radix_rust::ContextualDisplay;
5use sbor::prelude::fmt::Formatter;
6use sbor::rust::prelude::*;
7
8#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, ScryptoSbor, ManifestSbor)]
9pub struct BlueprintId {
10    pub package_address: PackageAddress,
11    pub blueprint_name: String,
12}
13
14impl BlueprintId {
15    pub fn new<S: ToString>(package_address: &PackageAddress, blueprint_name: S) -> Self {
16        BlueprintId {
17            package_address: *package_address,
18            blueprint_name: blueprint_name.to_string(),
19        }
20    }
21
22    #[allow(clippy::len_without_is_empty)]
23    pub fn len(&self) -> usize {
24        self.package_address.as_bytes().len() + self.blueprint_name.len()
25    }
26}
27
28impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for BlueprintId {
29    type Error = fmt::Error;
30
31    fn contextual_format(
32        &self,
33        f: &mut fmt::Formatter,
34        context: &AddressDisplayContext<'a>,
35    ) -> Result<(), Self::Error> {
36        write!(
37            f,
38            "{}:<{}>",
39            self.package_address.display(*context),
40            self.blueprint_name,
41        )
42    }
43}
44
45impl core::fmt::Debug for BlueprintId {
46    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
47        write!(f, "{}", self.display(NO_NETWORK))
48    }
49}