Skip to main content

open_timeline_core/
reduced.rs

1// SPDX-License-Identifier: MIT
2
3//!
4//! Reduced types
5//!
6
7mod entities;
8mod entity;
9mod timeline;
10mod timelines;
11
12pub use entities::*;
13pub use entity::*;
14pub use timeline::*;
15pub use timelines::*;
16
17use crate::{Name, OpenTimelineId};
18use std::collections::BTreeSet;
19
20// Defer to HasIdAndName trait?
21/// Implementing types are "reduced" types - they hold the ID and name of the
22/// full type, but nothing else
23pub trait IsReducedType {
24    /// Instantiate the reduced type using its ID and name
25    fn from_id_and_name(id: OpenTimelineId, name: Name) -> Self;
26
27    /// Get the name of the thing
28    fn name(&self) -> &Name;
29
30    /// Get the ID of the thing
31    fn id(&self) -> OpenTimelineId;
32}
33
34// TODO: Is this a good idea? Or should use use as_mut(), as_ref()?
35//
36// `<<Self as crate::crud::common::IsReducedCollection>::Item>` ensures that
37// Item here doesn't conflict with Item in the IntoIterator
38//
39/// Implementing types are collections of "reduced" types
40pub trait IsReducedCollection:
41    FromIterator<<Self as IsReducedCollection>::Item> + IntoIterator
42{
43    type Item: IsReducedType + Ord + Clone;
44
45    fn collection(&self) -> &BTreeSet<<Self as IsReducedCollection>::Item>;
46    fn collection_mut(&mut self) -> &mut BTreeSet<<Self as IsReducedCollection>::Item>;
47}