libwaj/common/
properties.rs1use crate::{
2 common::EntryType,
3 error::{BaseError, WajFormatError},
4};
5
6use jbk::{layout_builder, properties};
7
8properties! {
9 Property {
10 Path:"array" => "path",
11 Mimetype:"array" => "mimetype",
12 Content:"content" => "content",
13 Target:"array" => "target"
14 }
15}
16
17pub struct AllProperties {
18 pub store: jbk::reader::EntryStore,
19 pub path_property: jbk::reader::builder::ArrayProperty,
20 pub variant_id_property: jbk::reader::builder::VariantIdBuilder<EntryType>,
21 pub content_mimetype_property: jbk::reader::builder::ArrayProperty,
22 pub content_address_property: jbk::reader::builder::ContentProperty,
23 pub redirect_target_property: jbk::reader::builder::ArrayProperty,
24}
25
26impl AllProperties {
27 pub fn new(
28 store: jbk::reader::EntryStore,
29 value_storage: &jbk::reader::ValueStorage,
30 ) -> Result<Self, BaseError> {
31 let layout = store.layout();
32 if layout.variant_len() != 2 {
33 return Err(WajFormatError("Layout must contain 3 variants").into());
34 }
35 let path_property = layout_builder!(
36 layout[common][Property::Path],
37 value_storage,
38 WajFormatError
39 );
40 let variant_id_property = layout.variant_id_builder().expect("We have variants");
41 let content_mimetype_property = layout_builder!(
42 layout[EntryType::Content][Property::Mimetype],
43 value_storage,
44 WajFormatError
45 );
46 let content_address_property = layout_builder!(
47 layout[EntryType::Content][Property::Content],
48 value_storage,
49 WajFormatError
50 );
51 let redirect_target_property = layout_builder!(
52 layout[EntryType::Redirect][Property::Target],
53 value_storage,
54 WajFormatError
55 );
56 Ok(Self {
57 store,
58 path_property,
59 variant_id_property,
60 content_mimetype_property,
61 content_address_property,
62 redirect_target_property,
63 })
64 }
65}