radix_common/types/
blueprint_id.rsuse radix_common::address::{AddressDisplayContext, NO_NETWORK};
use radix_common::types::PackageAddress;
use radix_common::*;
use radix_rust::ContextualDisplay;
use sbor::prelude::fmt::Formatter;
use sbor::rust::prelude::*;
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, ScryptoSbor, ManifestSbor)]
pub struct BlueprintId {
pub package_address: PackageAddress,
pub blueprint_name: String,
}
impl BlueprintId {
pub fn new<S: ToString>(package_address: &PackageAddress, blueprint_name: S) -> Self {
BlueprintId {
package_address: *package_address,
blueprint_name: blueprint_name.to_string(),
}
}
pub fn len(&self) -> usize {
self.package_address.as_bytes().len() + self.blueprint_name.len()
}
}
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for BlueprintId {
type Error = fmt::Error;
fn contextual_format<F: fmt::Write>(
&self,
f: &mut F,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
write!(
f,
"{}:<{}>",
self.package_address.display(*context),
self.blueprint_name,
)
}
}
impl core::fmt::Debug for BlueprintId {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.display(NO_NETWORK))
}
}