1use crate::*;
2
3#[derive(Clone)]
4pub enum NDNId {
5 DirId(DirId),
6 FileId(FileId),
7 DiffId(DiffId),
8}
9
10#[derive(Clone)]
11pub enum NDNObject {
12 Dir(Dir),
13 File(File),
14 Diff(Diff),
15}
16
17impl NDNObject {
18 pub fn dir(&self) -> BuckyResult<&Dir> {
19 match self {
20 NDNObject::Dir(d) => Ok(d),
21 _ => Err(BuckyError::new(
22 BuckyErrorCode::InvalidParam,
23 "type is not Dir",
24 )),
25 }
26 }
27
28 pub fn file(&self) -> BuckyResult<&File> {
29 match self {
30 NDNObject::File(d) => Ok(d),
31 _ => Err(BuckyError::new(
32 BuckyErrorCode::ParseError,
33 "type is not File",
34 )),
35 }
36 }
37
38 pub fn diff(&self) -> BuckyResult<&Diff> {
39 match self {
40 NDNObject::Diff(d) => Ok(d),
41 _ => Err(BuckyError::new(
42 BuckyErrorCode::ParseError,
43 "type is not Diff",
44 )),
45 }
46 }
47
48 pub fn object_id(&self) -> ObjectId {
49 match self {
50 NDNObject::Dir(d) => d.desc().dir_id().object_id().clone(),
51 NDNObject::File(d) => d.desc().file_id().object_id().clone(),
52 NDNObject::Diff(d) => d.desc().diff_id().object_id().clone(),
53 }
54 }
55}