(&self)
| 116 | } |
| 117 | |
| 118 | fn project(&self) -> Projection { |
| 119 | let mut projection = Projection::default(); |
| 120 | for (id, effect) in &self.effects { |
| 121 | if self.active(*id) { |
| 122 | if let Effect::Bind { name, provider } = effect { |
| 123 | projection |
| 124 | .active_claims |
| 125 | .entry(name.clone()) |
| 126 | .or_default() |
| 127 | .insert(*id, *provider); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | let mut edges: BTreeMap<Hash, BTreeSet<Hash>> = BTreeMap::new(); |
| 132 | for (name, claims) in &projection.active_claims { |
| 133 | edges |
| 134 | .entry(name.consumer) |
| 135 | .or_default() |
| 136 | .extend(claims.values()); |
| 137 | } |
| 138 | fn cycle( |
| 139 | node: Hash, |
| 140 | edges: &BTreeMap<Hash, BTreeSet<Hash>>, |
| 141 | active: &mut BTreeSet<Hash>, |
| 142 | done: &mut BTreeSet<Hash>, |
| 143 | ) -> bool { |
| 144 | if done.contains(&node) { |
| 145 | return false; |
| 146 | } |
| 147 | if !active.insert(node) { |
| 148 | return true; |
| 149 | } |
| 150 | if edges.get(&node).is_some_and(|children| { |
| 151 | children |
| 152 | .iter() |
| 153 | .any(|next| cycle(*next, edges, active, done)) |
| 154 | }) { |
| 155 | return true; |
| 156 | } |
| 157 | active.remove(&node); |
| 158 | done.insert(node); |
| 159 | false |
| 160 | } |
| 161 | let mut done = BTreeSet::new(); |
| 162 | projection.cycle = edges |
| 163 | .keys() |
| 164 | .copied() |
| 165 | .any(|node| cycle(node, &edges, &mut BTreeSet::new(), &mut done)); |
| 166 | projection |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | fn bind(consumer: &str, provider: &str) -> Effect { |
no test coverage detected