cyfs_base/objects/
empty.rs

1use crate::*;
2use serde::Serialize;
3
4/// ## 提供一个空NamedObject定义
5/// 例如当一个泛型实现需要传入一个Option<N>参数,其中N是泛型NamedObject
6/// 则在需要传入None时,编译器要求指定具体的N类型,此时可以使用Empty来使得调用符合None的语义
7
8pub type EmptyType = NamedObjType<EmptyDescContent, EmptyBodyContent>;
9pub type Empty = NamedObjectBase<EmptyType>;
10
11#[derive(RawEncode, RawDecode, Clone)]
12pub struct EmptyDescContent {}
13
14impl DescContent for EmptyDescContent {
15    fn obj_type() -> u16 {
16        0u16
17    }
18    type OwnerType = SubDescNone;
19    type AreaType = SubDescNone;
20    type AuthorType = SubDescNone;
21    type PublicKeyType = SubDescNone;
22}
23
24/* An example of custom EmptyDescContent
25
26#[derive(Clone, Default, Serialize)]
27pub struct EmptyProtobufDescContent;
28
29impl DescContent for EmptyProtobufDescContent {
30    fn format(&self) -> u8 {
31        OBJECT_CONTENT_CODEC_FORMAT_PROTOBUF
32    }
33
34    fn obj_type() -> u16 {
35        xxx
36    }
37    type OwnerType = Option<ObjectId>;
38    type AreaType = SubDescNone;
39    type AuthorType = SubDescNone;
40    type PublicKeyType = SubDescNone;
41}
42
43cyfs_base::impl_empty_protobuf_raw_codec!(EmptyProtobufDescContent);
44*/
45
46
47// 两个默认的空body_content
48#[derive(Clone, Default, cyfs_base_derive::RawEncode, cyfs_base_derive::RawDecode, Serialize)]
49pub struct EmptyBodyContent;
50
51impl BodyContent for EmptyBodyContent {}
52
53#[derive(Clone, Default, Serialize)]
54pub struct EmptyProtobufBodyContent;
55
56impl BodyContent for EmptyProtobufBodyContent {
57    fn format(&self) -> u8 {
58        OBJECT_CONTENT_CODEC_FORMAT_PROTOBUF
59    }
60}
61
62crate::inner_impl_empty_protobuf_raw_codec!(EmptyProtobufBodyContent);