mangofetch_core/core/
registry.rs1use std::sync::Arc;
2
3use crate::platforms::traits::PlatformDownloader;
4
5pub struct PlatformRegistry {
6 platforms: Vec<Arc<dyn PlatformDownloader>>,
7}
8
9impl PlatformRegistry {
10 pub fn new() -> Self {
11 Self {
12 platforms: Vec::new(),
13 }
14 }
15
16 pub fn register(&mut self, platform: Arc<dyn PlatformDownloader>) {
17 self.platforms.push(platform);
18 }
19
20 pub fn find_platform(&self, url: &str) -> Option<Arc<dyn PlatformDownloader>> {
21 self.platforms.iter().find(|p| p.can_handle(url)).cloned()
22 }
23
24 pub fn find_by_name(&self, name: &str) -> Option<Arc<dyn PlatformDownloader>> {
25 self.platforms.iter().find(|p| p.name() == name).cloned()
26 }
27}
28
29impl Default for PlatformRegistry {
30 fn default() -> Self {
31 Self::new()
32 }
33}