move_core_types/
move_resource.rs

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