Skip to main content

outmove_common/types/
move_resource.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4use super::{
5    identifier::{IdentStr, Identifier},
6    language_storage::{StructTag, TypeTag},
7};
8
9pub trait MoveResource {
10    const MODULE_NAME: &'static str;
11    const STRUCT_NAME: &'static str;
12
13    fn module_identifier() -> Identifier {
14        IdentStr::new(Self::MODULE_NAME)
15            .expect("failed to get IdentStr for Move module")
16            .to_owned()
17    }
18
19    fn struct_identifier() -> Identifier {
20        IdentStr::new(Self::STRUCT_NAME)
21            .expect("failed to get IdentStr for Move struct")
22            .to_owned()
23    }
24
25    fn type_params() -> Vec<TypeTag> {
26        vec![]
27    }
28
29    fn struct_tag() -> StructTag {
30        StructTag {
31            address: crate::types::language_storage::CORE_CODE_ADDRESS,
32            name: Self::struct_identifier(),
33            module: Self::module_identifier(),
34            type_params: Self::type_params(),
35        }
36    }
37
38    fn resource_path() -> Vec<u8> {
39        Self::struct_tag().access_vector()
40    }
41}