oo_bindgen/model/
collection.rs

1use crate::model::*;
2
3#[derive(Debug)]
4pub struct Collection<D>
5where
6    D: DocReference,
7{
8    pub(crate) collection_class: ClassDeclarationHandle,
9    pub(crate) item_type: FunctionArgument,
10    pub(crate) create_func: Handle<Function<D>>,
11    pub(crate) delete_func: Handle<Function<D>>,
12    pub(crate) add_func: Handle<Function<D>>,
13    pub(crate) has_reserve: bool,
14}
15
16impl<D> Collection<D>
17where
18    D: DocReference,
19{
20    pub(crate) fn new(
21        collection_class: ClassDeclarationHandle,
22        item_type: FunctionArgument,
23        create_func: Handle<Function<D>>,
24        delete_func: Handle<Function<D>>,
25        add_func: Handle<Function<D>>,
26        has_reserve: bool,
27    ) -> Collection<D> {
28        Collection {
29            collection_class,
30            item_type,
31            create_func,
32            delete_func,
33            add_func,
34            has_reserve,
35        }
36    }
37
38    pub fn name(&self) -> &Name {
39        &self.collection_class.name
40    }
41}
42
43impl Collection<Unvalidated> {
44    pub(crate) fn validate(
45        &self,
46        lib: &LibraryFields,
47    ) -> BindResult<Handle<Collection<Validated>>> {
48        Ok(Handle::new(Collection {
49            collection_class: self.collection_class.clone(),
50            item_type: self.item_type.clone(),
51            create_func: self.create_func.validate(lib)?,
52            delete_func: self.delete_func.validate(lib)?,
53            add_func: self.add_func.validate(lib)?,
54            has_reserve: self.has_reserve,
55        }))
56    }
57}
58
59pub type CollectionHandle = Handle<Collection<Unvalidated>>;