Skip to main content

radix_common/types/addresses/
mod.rs

1mod component_address;
2mod global_address;
3mod internal_address;
4mod package_address;
5mod resource_address;
6
7pub use component_address::*;
8pub use global_address::*;
9pub use internal_address::*;
10pub use package_address::*;
11pub use resource_address::*;
12
13use crate::types::{EntityType, NodeId};
14
15pub const fn component_address(entity_type: EntityType, last_byte: u8) -> ComponentAddress {
16    let mut node_id = [0u8; NodeId::LENGTH];
17    node_id[0] = entity_type as u8;
18    node_id[NodeId::LENGTH - 1] = last_byte;
19    ComponentAddress::new_or_panic(node_id)
20}
21
22pub const fn resource_address(entity_type: EntityType, last_byte: u8) -> ResourceAddress {
23    let mut node_id = [0u8; NodeId::LENGTH];
24    node_id[0] = entity_type as u8;
25    node_id[NodeId::LENGTH - 1] = last_byte;
26    ResourceAddress::new_or_panic(node_id)
27}
28
29pub const fn package_address(entity_type: EntityType, last_byte: u8) -> PackageAddress {
30    let mut node_id = [0u8; NodeId::LENGTH];
31    node_id[0] = entity_type as u8;
32    node_id[NodeId::LENGTH - 1] = last_byte;
33    PackageAddress::new_or_panic(node_id)
34}
35
36pub const fn local_address(entity_type: EntityType, last_byte: u8) -> InternalAddress {
37    let mut node_id = [0u8; NodeId::LENGTH];
38    node_id[0] = entity_type as u8;
39    node_id[NodeId::LENGTH - 1] = last_byte;
40    InternalAddress::new_or_panic(node_id)
41}