pcp/term/
ops.rs

1// Copyright 2015 Pierre Talbot (IRCAM)
2
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6
7//     http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use gcollections::kind::*;
16use std::ops::{Deref, DerefMut};
17
18pub trait StoreMonotonicUpdate<Store: Collection>
19{
20  fn update(&mut self, store: &mut Store, value: Store::Item) -> bool;
21}
22
23pub trait StoreRead<Store: Collection>
24{
25  fn read(&self, store: &Store) -> Store::Item;
26}
27
28pub trait ViewDependencies<Event>
29{
30  fn dependencies(&self, event: Event) -> Vec<(usize, Event)>;
31}
32
33impl<Store, R> StoreMonotonicUpdate<Store> for Box<R> where
34  R: StoreMonotonicUpdate<Store>,
35  Store: Collection
36{
37  fn update(&mut self, store: &mut Store, value: Store::Item) -> bool {
38    self.deref_mut().update(store, value)
39  }
40}
41
42impl<Store, R> StoreRead<Store> for Box<R> where
43  R: StoreRead<Store>,
44  Store: Collection
45{
46  fn read(&self, store: &Store) -> Store::Item {
47    self.deref().read(store)
48  }
49}
50
51impl<Event, R> ViewDependencies<Event> for Box<R> where
52  R: ViewDependencies<Event>
53{
54  fn dependencies(&self, event: Event) -> Vec<(usize, Event)> {
55    self.deref().dependencies(event)
56  }
57}