cyfs_core/nft/
nft_list.rs1use cyfs_base::*;
2use crate::CoreObjectType;
3
4
5#[derive(ProtobufEncode, ProtobufDecode, ProtobufTransformType, Clone, Debug)]
6#[cyfs_protobuf_type(crate::codec::protos::NftListDescContent)]
7pub struct NFTListDescContent {
8 pub nft_list: Vec<FileDesc>,
9}
10
11impl ProtobufTransform<crate::codec::protos::NftListDescContent> for NFTListDescContent {
12 fn transform(value: crate::codec::protos::NftListDescContent) -> BuckyResult<Self> {
13 let mut nft_list = Vec::new();
14 for nft in value.nft_list.iter() {
15 nft_list.push(FileDesc::clone_from_slice(nft.desc.as_slice())?);
16 }
17
18 Ok(Self {
19 nft_list
20 })
21 }
22}
23
24impl ProtobufTransform<&NFTListDescContent> for crate::codec::protos::NftListDescContent {
25 fn transform(value: &NFTListDescContent) -> BuckyResult<Self> {
26 let mut nft_list = Vec::new();
27 for nft in value.nft_list.iter() {
28 nft_list.push(crate::codec::protos::NftFileDesc {
29 desc: nft.to_vec()?
30 });
31 }
32
33 Ok(Self {
34 nft_list
35 })
36 }
37}
38
39impl DescContent for NFTListDescContent {
40 fn obj_type() -> u16 {
41 CoreObjectType::NFTList as u16
42 }
43
44 type OwnerType = Option<ObjectId>;
45 type AreaType = SubDescNone;
46 type AuthorType = Option<ObjectId>;
47 type PublicKeyType = SubDescNone;
48}
49
50pub type NFTListDesc = NamedObjectDesc<NFTListDescContent>;
51pub type NFTListType = NamedObjType<NFTListDescContent, EmptyProtobufBodyContent>;
52pub type NFTListBuilder = NamedObjectBuilder<NFTListDescContent, EmptyProtobufBodyContent>;
53pub type NFTList = NamedObjectBase<NFTListType>;
54
55pub trait NFTListObject {
56 fn new(owner_id: ObjectId, nft_list: Vec<FileDesc>) -> Self;
57 fn nft_list(&self) -> &Vec<FileDesc>;
58 fn into_nft_list(self) -> Vec<FileDesc>;
59}
60
61impl NFTListObject for NFTList {
62 fn new(owner_id: ObjectId, nft_list: Vec<FileDesc>) -> Self {
63 let desc = NFTListDescContent {
64 nft_list
65 };
66 NFTListBuilder::new(desc, EmptyProtobufBodyContent::default()).owner(owner_id).build()
67 }
68
69 fn nft_list(&self) -> &Vec<FileDesc> {
70 &self.desc().content().nft_list
71 }
72
73 fn into_nft_list(self) -> Vec<FileDesc> {
74 self.into_desc().into_content().nft_list
75 }
76}