1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
use rayon::prelude::IntoParallelIterator;
use semver::Version;
use crate::{
Bundle, Info, Loader, Manager, Plugin, Registry, Requests,
utils::{
CallFunctionDependError, LoadPluginError, PluginCallFunctionError, PluginCallRequestError,
PluginOperationError, Ptr, RegisterManagerError, RegisterPluginError, UnloadPluginError,
UnregisterManagerError, UnregisterPluginError,
},
variable::Variable,
};
/// API interface provided to plugins during loading.
///
/// The Api struct provides a controlled interface for plugins to interact with the Plux system.
/// It allows plugins to access the loader's functionality while maintaining security boundaries
/// and providing dependency-aware operations.
///
/// # Type Parameters
///
/// * `O` - Output type for plugin functions (must implement Send + Sync + 'static)
/// * `I` - Plugin information type (must implement Info + 'static)
///
/// # Fields
///
/// * `loader` - Reference to the underlying loader
/// * `plugin` - Bundle information for the current plugin
/// * `depends` - List of required dependencies for this plugin
/// * `optional_depends` - List of optional dependencies for this plugin
pub struct Api<O: Send + Sync + 'static, I: Info + 'static> {
loader: Ptr<'static, Loader<'static, O, I>>,
plugin: Bundle,
depends: Vec<Bundle>,
optional_depends: Vec<Bundle>,
}
impl<O: Send + Sync + 'static, I: Info + 'static> Api<O, I> {
/// Creates a new API instance for a plugin.
///
/// This is an internal constructor used by the loader when loading plugins.
///
/// # Parameters
///
/// * `loader` - Reference to the loader
/// * `plugin` - Bundle information for the plugin
/// * `depends` - Required dependencies
/// * `optional_depends` - Optional dependencies
///
/// # Returns
///
/// Returns a new Api instance.
pub(crate) const fn new(
loader: Ptr<'static, Loader<'static, O, I>>,
plugin: Bundle,
depends: Vec<Bundle>,
optional_depends: Vec<Bundle>,
) -> Self {
Self {
loader,
plugin,
depends,
optional_depends,
}
}
/// Gets access to the function registry.
///
/// Returns a reference to the registry containing all functions available to plugins.
///
/// # Returns
///
/// Returns `&Registry<O>` containing the function registry.
pub fn registry(&self) -> &Registry<O> {
&self.loader.as_ref().registry
}
/// Gets information about the current plugin.
///
/// Returns the bundle information for the plugin this API instance belongs to.
///
/// # Returns
///
/// Returns `&Bundle` containing plugin metadata.
pub const fn plugin(&self) -> &Bundle {
&self.plugin
}
/// Gets the list of required dependencies.
///
/// Returns all dependencies that must be available for this plugin to function.
///
/// # Returns
///
/// Returns `&Vec<Bundle>` containing required dependencies.
pub const fn depends(&self) -> &Vec<Bundle> {
&self.depends
}
/// Gets the list of optional dependencies.
///
/// Returns all optional dependencies that enhance this plugin's functionality but are not required.
///
/// # Returns
///
/// Returns `&Vec<Bundle>` containing optional dependencies.
pub const fn optional_depends(&self) -> &Vec<Bundle> {
&self.optional_depends
}
// Loader functions
/// Registers a plugin manager with the loader.
///
/// This method allows plugins to register new managers during execution.
///
/// # Parameters
///
/// * `manager` - The manager instance to register
///
/// # Returns
///
/// Returns `Result<(), RegisterManagerError>` indicating success or failure.
///
/// # Type Parameters
///
/// * `M` - Type of the manager (must implement Manager trait)
pub fn register_manager<M>(&self, manager: M) -> Result<(), RegisterManagerError>
where
M: Manager<'static, O, I> + 'static,
{
self.loader.as_mut().register_manager(manager)
}
/// Registers multiple plugin managers with the loader.
///
/// This method allows plugins to register multiple managers in sequence.
///
/// # Parameters
///
/// * `managers` - Iterator of manager instances to register
///
/// # Returns
///
/// Returns `Result<(), RegisterManagerError>` indicating success or failure.
pub fn register_managers<M>(&self, managers: M) -> Result<(), RegisterManagerError>
where
M: IntoIterator<Item = Box<dyn Manager<'static, O, I>>>,
{
self.loader.as_mut().register_managers(managers)
}
/// Registers multiple plugin managers with the loader in parallel.
///
/// This method allows plugins to register multiple managers concurrently.
///
/// # Parameters
///
/// * `managers` - Parallel iterator of manager instances to register
///
/// # Returns
///
/// Returns `Result<(), RegisterManagerError>` indicating success or failure.
pub fn par_register_managers<M>(&self, managers: M) -> Result<(), RegisterManagerError>
where
M: IntoParallelIterator<Item = Box<dyn Manager<'static, O, I>>>,
{
self.loader.as_mut().par_register_managers(managers)
}
/// Unregisters a plugin manager from the loader.
///
/// This method allows plugins to unregister managers by format.
///
/// # Parameters
///
/// * `format` - The format of the manager to unregister
///
/// # Returns
///
/// Returns `Result<(), UnregisterManagerError>` indicating success or failure.
pub fn unregister_manager(&self, format: &str) -> Result<(), UnregisterManagerError> {
self.loader.as_mut().unregister_manager(format)
}
/// Gets an immutable reference to a manager by format.
///
/// This method allows plugins to access registered managers.
///
/// # Parameters
///
/// * `format` - The format of the manager to retrieve
///
/// # Returns
///
/// Returns `Option<&Box<dyn Manager<'static, O, I>>>` containing the manager if found.
pub fn get_manager_ref(&self, format: &str) -> Option<&Box<dyn Manager<'static, O, I>>> {
self.loader.as_ref().get_manager_ref(format)
}
/// Gets an immutable reference to a manager by format (parallel version).
///
/// This method allows plugins to access registered managers using parallel processing.
///
/// # Parameters
///
/// * `format` - The format of the manager to retrieve
///
/// # Returns
///
/// Returns `Option<&Box<dyn Manager<'static, O, I>>>` containing the manager if found.
pub fn par_get_manager_ref(&self, format: &str) -> Option<&Box<dyn Manager<'static, O, I>>> {
self.loader.as_ref().par_get_manager_ref(format)
}
/// Gets a mutable reference to a manager by format.
///
/// This method allows plugins to access registered managers for modification.
///
/// # Parameters
///
/// * `format` - The format of the manager to retrieve
///
/// # Returns
///
/// Returns `Option<&mut Box<dyn Manager<'static, O, I>>>` containing the manager if found.
pub fn get_manager_mut(&self, format: &str) -> Option<&mut Box<dyn Manager<'static, O, I>>> {
self.loader.as_mut().get_manager_mut(format)
}
/// Gets a mutable reference to a manager by format (parallel version).
///
/// This method allows plugins to access registered managers for modification using parallel processing.
///
/// # Parameters
///
/// * `format` - The format of the manager to retrieve
///
/// # Returns
///
/// Returns `Option<&mut Box<dyn Manager<'static, O, I>>>` containing the manager if found.
pub fn par_get_manager_mut(
&self,
format: &str,
) -> Option<&mut Box<dyn Manager<'static, O, I>>> {
self.loader.as_mut().par_get_manager_mut(format)
}
/// Registers a plugin with the loader.
///
/// This method allows plugins to register new plugins during execution.
///
/// # Parameters
///
/// * `path` - Path to the plugin file or directory
///
/// # Returns
///
/// Returns `Result<Bundle, RegisterPluginError>` containing the plugin bundle on success.
pub fn register_plugin(&self, path: &str) -> Result<Bundle, RegisterPluginError> {
self.loader.as_mut().register_plugin(path)
}
/// Registers multiple plugins with the loader.
///
/// This method allows plugins to register multiple plugins in sequence.
///
/// # Parameters
///
/// * `paths` - Iterator of paths to plugin files or directories
///
/// # Returns
///
/// Returns `Result<Vec<Bundle>, RegisterPluginError>` containing the plugin bundles on success.
///
/// # Type Parameters
///
/// * `'b` - Lifetime of the path references
/// * `P` - Type of the iterator containing path references
pub fn register_plugins<'b, P>(&self, paths: P) -> Result<Vec<Bundle>, RegisterPluginError>
where
P: IntoIterator<Item = &'b str>,
{
self.loader.as_mut().register_plugins(paths)
}
/// Registers multiple plugins with the loader in parallel.
///
/// This method allows plugins to register multiple plugins concurrently.
///
/// # Parameters
///
/// * `paths` - Parallel iterator of paths to plugin files or directories
///
/// # Returns
///
/// Returns `Result<Vec<Bundle>, RegisterPluginError>` containing the plugin bundles on success.
///
/// # Type Parameters
///
/// * `'b` - Lifetime of the path references
/// * `P` - Type of the parallel iterator containing path references
pub fn par_register_plugins<'b, P>(&self, paths: P) -> Result<Vec<Bundle>, RegisterPluginError>
where
P: IntoParallelIterator<Item = &'b str>,
{
self.loader.as_mut().par_register_plugins(paths)
}
/// Unregisters a plugin from the loader.
///
/// This method allows plugins to unregister plugins by ID and version.
///
/// # Parameters
///
/// * `id` - Plugin identifier
/// * `version` - Plugin version
///
/// # Returns
///
/// Returns `Result<(), UnregisterPluginError>` indicating success or failure.
pub fn unregister_plugin(
&self,
id: &str,
version: &Version,
) -> Result<(), UnregisterPluginError> {
self.loader.as_mut().unregister_plugin(id, version)
}
/// Unregisters a plugin from the loader by bundle.
///
/// This method allows plugins to unregister plugins by bundle information.
///
/// # Parameters
///
/// * `bundle` - Plugin bundle information
///
/// # Returns
///
/// Returns `Result<(), UnregisterPluginError>` indicating success or failure.
pub fn unregister_plugin_by_bundle(
&self,
bundle: &Bundle,
) -> Result<(), UnregisterPluginError> {
self.loader.as_mut().unregister_plugin_by_bundle(bundle)
}
/// Unregisters a plugin from the loader by bundle (parallel version).
///
/// This method allows plugins to unregister plugins by bundle information using parallel processing.
///
/// # Parameters
///
/// * `bundle` - Plugin bundle information
///
/// # Returns
///
/// Returns `Result<(), UnregisterPluginError>` indicating success or failure.
pub fn par_unregister_plugin_by_bundle(
&self,
bundle: &Bundle,
) -> Result<(), UnregisterPluginError> {
self.loader.as_mut().par_unregister_plugin_by_bundle(bundle)
}
/// Loads a plugin into the execution environment.
///
/// This method allows plugins to load other plugins by ID and version.
///
/// # Parameters
///
/// * `id` - Plugin identifier
/// * `version` - Plugin version
///
/// # Returns
///
/// Returns `Result<(), LoadPluginError>` indicating success or failure.
pub fn load_plugin(&self, id: &str, version: &Version) -> Result<(), LoadPluginError> {
self.loader.as_mut().load_plugin(id, version)
}
/// Loads a plugin into the execution environment (parallel version).
///
/// This method allows plugins to load other plugins by ID and version using parallel processing.
///
/// # Parameters
///
/// * `id` - Plugin identifier
/// * `version` - Plugin version
///
/// # Returns
///
/// Returns `Result<(), LoadPluginError>` indicating success or failure.
pub fn par_load_plugin(&self, id: &str, version: &Version) -> Result<(), LoadPluginError> {
self.loader.as_mut().par_load_plugin(id, version)
}
/// Loads a plugin into the execution environment by bundle.
///
/// This method allows plugins to load other plugins by bundle information.
///
/// # Parameters
///
/// * `bundle` - Plugin bundle information
///
/// # Returns
///
/// Returns `Result<(), LoadPluginError>` indicating success or failure.
pub fn load_plugin_by_bundle(&self, bundle: &Bundle) -> Result<(), LoadPluginError> {
self.loader.as_mut().load_plugin_by_bundle(bundle)
}
/// Loads a plugin into the execution environment by bundle (parallel version).
///
/// This method allows plugins to load other plugins by bundle information using parallel processing.
///
/// # Parameters
///
/// * `bundle` - Plugin bundle information
///
/// # Returns
///
/// Returns `Result<(), LoadPluginError>` indicating success or failure.
pub fn par_load_plugin_by_bundle(&self, bundle: &Bundle) -> Result<(), LoadPluginError> {
self.loader.as_mut().par_load_plugin_by_bundle(bundle)
}
/// Loads a plugin immediately from the specified path.
///
/// This convenience method allows plugins to register and load a plugin in a single operation.
///
/// # Parameters
///
/// * `path` - Path to the plugin file or directory
///
/// # Returns
///
/// Returns `Result<Bundle, PluginOperationError>`
/// containing the plugin bundle on success, or errors from registration or loading.
pub fn load_plugin_now(&self, path: &str) -> Result<Bundle, PluginOperationError> {
self.loader.as_mut().load_plugin_now(path)
}
/// Loads multiple plugins from the specified paths.
///
/// This method allows plugins to register and load multiple plugins in sequence.
///
/// # Parameters
///
/// * `paths` - Iterator of paths to plugin files or directories
///
/// # Returns
///
/// Returns `Result<Vec<Bundle>, PluginOperationError>`
/// containing the plugin bundles on success, or errors from registration or loading.
///
/// # Type Parameters
///
/// * `'b` - Lifetime of the path references
/// * `P` - Type of the iterator containing path references
pub fn load_plugins<'b, P>(&self, paths: P) -> Result<Vec<Bundle>, PluginOperationError>
where
P: IntoIterator<Item = &'b str>,
{
self.loader.as_mut().load_plugins(paths)
}
/// Loads multiple plugins from the specified paths (parallel version).
///
/// This method allows plugins to register and load multiple plugins concurrently.
///
/// # Parameters
///
/// * `paths` - Parallel iterator of paths to plugin files or directories
///
/// # Returns
///
/// Returns `Result<Vec<Bundle>, PluginOperationError>`
/// containing the plugin bundles on success, or errors from registration or loading.
///
/// # Type Parameters
///
/// * `'b` - Lifetime of the path references
/// * `P` - Type of the parallel iterator containing path references
pub fn par_load_plugins<'b, P>(&self, paths: P) -> Result<Vec<Bundle>, PluginOperationError>
where
P: IntoParallelIterator<Item = &'b str>,
{
self.loader.as_mut().par_load_plugins(paths)
}
/// Loads only the plugins that are used (not dependencies of other plugins).
///
/// This method allows plugins to register and load only the plugins that are not
/// dependencies of other plugins, and automatically unregisters unused plugins.
///
/// # Parameters
///
/// * `paths` - Iterator of paths to plugin files or directories
///
/// # Returns
///
/// Returns `Result<Vec<Bundle>, PluginOperationError>`
/// containing the plugin bundles on success, or errors from registration, unregistration, or loading.
///
/// # Type Parameters
///
/// * `'b` - Lifetime of the path references
/// * `P` - Type of the iterator containing path references
pub fn load_only_used_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, PluginOperationError>
where
P: IntoIterator<Item = &'b str>,
{
self.loader.as_mut().load_only_used_plugins(paths)
}
/// Loads only the plugins that are used (not dependencies of other plugins) (parallel version).
///
/// This method allows plugins to register and load only the plugins that are not
/// dependencies of other plugins using parallel processing, and automatically unregisters unused plugins.
///
/// # Parameters
///
/// * `paths` - Parallel iterator of paths to plugin files or directories
///
/// # Returns
///
/// Returns `Result<Vec<Bundle>, PluginOperationError>`
/// containing the plugin bundles on success, or errors from registration, unregistration, or loading.
///
/// # Type Parameters
///
/// * `'b` - Lifetime of the path references
/// * `P` - Type of the parallel iterator containing path references
pub fn par_load_only_used_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, PluginOperationError>
where
P: IntoParallelIterator<Item = &'b str>,
{
self.loader.as_mut().par_load_only_used_plugins(paths)
}
/// Unloads a plugin from the execution environment.
///
/// This method allows plugins to unload other plugins by ID and version.
///
/// # Parameters
///
/// * `id` - Plugin identifier
/// * `version` - Plugin version
///
/// # Returns
///
/// Returns `Result<(), UnloadPluginError>` indicating success or failure.
pub fn unload_plugin(&self, id: &str, version: &Version) -> Result<(), UnloadPluginError> {
self.loader.as_mut().unload_plugin(id, version)
}
/// Unloads a plugin from the execution environment (parallel version).
///
/// This method allows plugins to unload other plugins by ID and version using parallel processing.
///
/// # Parameters
///
/// * `id` - Plugin identifier
/// * `version` - Plugin version
///
/// # Returns
///
/// Returns `Result<(), UnloadPluginError>` indicating success or failure.
pub fn par_unload_plugin(&self, id: &str, version: &Version) -> Result<(), UnloadPluginError> {
self.loader.as_mut().par_unload_plugin(id, version)
}
/// Unloads a plugin from the execution environment by bundle.
///
/// This method allows plugins to unload other plugins by bundle information.
///
/// # Parameters
///
/// * `bundle` - Plugin bundle information
///
/// # Returns
///
/// Returns `Result<(), UnloadPluginError>` indicating success or failure.
pub fn unload_plugin_by_bundle(&self, bundle: &Bundle) -> Result<(), UnloadPluginError> {
self.loader.as_mut().unload_plugin_by_bundle(bundle)
}
/// Unloads a plugin from the execution environment by bundle (parallel version).
///
/// This method allows plugins to unload other plugins by bundle information using parallel processing.
///
/// # Parameters
///
/// * `bundle` - Plugin bundle information
///
/// # Returns
///
/// Returns `Result<(), UnloadPluginError>` indicating success or failure.
pub fn par_unload_plugin_by_bundle(&self, bundle: &Bundle) -> Result<(), UnloadPluginError> {
self.loader.as_mut().par_unload_plugin_by_bundle(bundle)
}
/// Gets an immutable reference to a plugin by ID and version.
///
/// This method allows plugins to access other registered plugins.
///
/// # Parameters
///
/// * `id` - Plugin identifier
/// * `version` - Plugin version
///
/// # Returns
///
/// Returns `Option<&Plugin<'static, O, I>>` containing the plugin if found.
pub fn get_plugin(&self, id: &str, version: &Version) -> Option<&Plugin<'static, O, I>> {
self.loader.as_ref().get_plugin(id, version)
}
/// Gets an immutable reference to a plugin by ID and version (parallel version).
///
/// This method allows plugins to access other registered plugins using parallel processing.
///
/// # Parameters
///
/// * `id` - Plugin identifier
/// * `version` - Plugin version
///
/// # Returns
///
/// Returns `Option<&Plugin<'static, O, I>>` containing the plugin if found.
pub fn par_get_plugin(&self, id: &str, version: &Version) -> Option<&Plugin<'static, O, I>> {
self.loader.as_ref().par_get_plugin(id, version)
}
/// Gets an immutable reference to a plugin by bundle.
///
/// This method allows plugins to access other registered plugins by bundle information.
///
/// # Parameters
///
/// * `bundle` - Plugin bundle information
///
/// # Returns
///
/// Returns `Option<&Plugin<'static, O, I>>` containing the plugin if found.
pub fn get_plugin_by_bundle(&self, bundle: &Bundle) -> Option<&Plugin<'static, O, I>> {
self.loader.as_ref().get_plugin_by_bundle(bundle)
}
/// Gets an immutable reference to a plugin by bundle (parallel version).
///
/// This method allows plugins to access other registered plugins by bundle information using parallel processing.
///
/// # Parameters
///
/// * `bundle` - Plugin bundle information
///
/// # Returns
///
/// Returns `Option<&Plugin<'static, O, I>>` containing the plugin if found.
pub fn par_get_plugin_by_bundle(&self, bundle: &Bundle) -> Option<&Plugin<'static, O, I>> {
self.loader.as_ref().par_get_plugin_by_bundle(bundle)
}
/// Gets a mutable reference to a plugin by ID and version.
///
/// This method allows plugins to access other registered plugins for modification.
///
/// # Parameters
///
/// * `id` - Plugin identifier
/// * `version` - Plugin version
///
/// # Returns
///
/// Returns `Option<&mut Plugin<'static, O, I>>` containing the plugin if found.
pub fn get_plugin_mut(
&self,
id: &str,
version: &Version,
) -> Option<&mut Plugin<'static, O, I>> {
self.loader.as_mut().get_plugin_mut(id, version)
}
/// Gets a mutable reference to a plugin by ID and version (parallel version).
///
/// This method allows plugins to access other registered plugins for modification using parallel processing.
///
/// # Parameters
///
/// * `id` - Plugin identifier
/// * `version` - Plugin version
///
/// # Returns
///
/// Returns `Option<&mut Plugin<'static, O, I>>` containing the plugin if found.
pub fn par_get_plugin_mut(
&self,
id: &str,
version: &Version,
) -> Option<&mut Plugin<'static, O, I>> {
self.loader.as_mut().par_get_plugin_mut(id, version)
}
/// Gets a mutable reference to a plugin by bundle.
///
/// This method allows plugins to access other registered plugins for modification by bundle information.
///
/// # Parameters
///
/// * `bundle` - Plugin bundle information
///
/// # Returns
///
/// Returns `Option<&mut Plugin<'static, O, I>>` containing the plugin if found.
pub fn get_plugin_mut_by_bundle(&self, bundle: &Bundle) -> Option<&mut Plugin<'static, O, I>> {
self.loader.as_mut().get_plugin_mut_by_bundle(bundle)
}
/// Gets a mutable reference to a plugin by bundle (parallel version).
///
/// This method allows plugins to access other registered plugins for modification by bundle information using parallel processing.
///
/// # Parameters
///
/// * `bundle` - Plugin bundle information
///
/// # Returns
///
/// Returns `Option<&mut Plugin<'static, O, I>>` containing the plugin if found.
pub fn par_get_plugin_mut_by_bundle(
&self,
bundle: &Bundle,
) -> Option<&mut Plugin<'static, O, I>> {
self.loader.as_mut().par_get_plugin_mut_by_bundle(bundle)
}
/// Gets all plugins with the specified ID.
///
/// This method allows plugins to access all versions of plugins with a specific ID.
///
/// # Parameters
///
/// * `id` - Plugin identifier to search for
///
/// # Returns
///
/// Returns `Vec<&Plugin<'static, O, I>>` containing all matching plugins.
pub fn get_plugins_by_id(&self, id: &str) -> Vec<&Plugin<'static, O, I>> {
self.loader.as_ref().get_plugins_by_id(id)
}
/// Gets all plugins with the specified ID (parallel version).
///
/// This method allows plugins to access all versions of plugins with a specific ID using parallel processing.
///
/// # Parameters
///
/// * `id` - Plugin identifier to search for
///
/// # Returns
///
/// Returns `Vec<&Plugin<'static, O, I>>` containing all matching plugins.
pub fn par_get_plugins_by_id(&self, id: &str) -> Vec<&Plugin<'static, O, I>> {
self.loader.as_ref().par_get_plugins_by_id(id)
}
/// Gets mutable references to all plugins with the specified ID.
///
/// This method allows plugins to access all versions of plugins with a specific ID for modification.
///
/// # Parameters
///
/// * `id` - Plugin identifier to search for
///
/// # Returns
///
/// Returns `Vec<&mut Plugin<'static, O, I>>` containing all matching plugins.
pub fn get_plugins_by_id_mut(&self, id: &str) -> Vec<&mut Plugin<'static, O, I>> {
self.loader.as_mut().get_plugins_by_id_mut(id)
}
/// Gets mutable references to all plugins with the specified ID (parallel version).
///
/// This method allows plugins to access all versions of plugins with a specific ID for modification using parallel processing.
///
/// # Parameters
///
/// * `id` - Plugin identifier to search for
///
/// # Returns
///
/// Returns `Vec<&mut Plugin<'static, O, I>>` containing all matching plugins.
pub fn par_get_plugins_by_id_mut(&self, id: &str) -> Vec<&mut Plugin<'static, O, I>> {
self.loader.as_mut().par_get_plugins_by_id_mut(id)
}
/// Gets a reference to all loaded plugins.
///
/// This method allows plugins to access the complete list of loaded plugins.
///
/// # Returns
///
/// Returns `&Vec<Plugin<'static, O, I>>` containing all loaded plugins.
pub fn get_plugins(&self) -> &Vec<Plugin<'static, O, I>> {
self.loader.as_ref().get_plugins()
}
/// Gets a reference to the function registry.
///
/// This method allows plugins to access the registry of functions available to plugins.
///
/// # Returns
///
/// Returns `&Registry<O>` containing the function registry.
pub fn get_registry(&self) -> &Registry<O> {
self.loader.as_ref().get_registry()
}
/// Gets a reference to the function requests.
///
/// This method allows plugins to access the collection of function requests.
///
/// # Returns
///
/// Returns `&Requests` containing the function requests.
pub fn get_requests(&self) -> &Requests {
self.loader.as_ref().get_requests()
}
/// Calls a function request across all eligible plugins.
///
/// This method allows plugins to call a function request on all plugins that have the highest
/// version for their ID (to avoid calling multiple versions of the same plugin).
///
/// # Parameters
///
/// * `name` - Name of the function request to call
/// * `args` - Arguments to pass to the function
///
/// # Returns
///
/// Returns `Result<Vec<O>, PluginCallRequestError>` containing results from all
/// eligible plugins that have the requested function.
pub fn call_request(
&self,
name: &str,
args: &[Variable],
) -> Result<Vec<O>, PluginCallRequestError> {
self.loader.as_ref().call_request(name, args)
}
/// Calls a function request across all eligible plugins (parallel version).
///
/// This method allows plugins to call a function request on all plugins that have the highest
/// version for their ID using parallel processing.
///
/// # Parameters
///
/// * `name` - Name of the function request to call
/// * `args` - Arguments to pass to the function
///
/// # Returns
///
/// Returns `Result<Vec<O>, PluginCallRequestError>` containing results from all
/// eligible plugins that have the requested function.
pub fn par_call_request(
&self,
name: &str,
args: &[Variable],
) -> Result<Vec<O>, PluginCallRequestError> {
self.loader.as_ref().par_call_request(name, args)
}
/// Calls a function on a required dependency.
///
/// This method allows the current plugin to call functions exposed by its required dependencies.
/// It ensures that the dependency exists and is loaded before attempting the call.
///
/// # Parameters
///
/// * `id` - Dependency plugin ID
/// * `version` - Dependency plugin version
/// * `name` - Function name to call
/// * `args` - Arguments to pass to the function
///
/// # Returns
///
/// Returns `Result<O, CallFunctionDependError>` containing the function result on success,
/// or an error if the dependency is not found or the function call fails.
///
/// # Note
///
/// This method only works with required dependencies. For optional dependencies,
/// use `call_function_optional_depend`.
pub fn call_function_depend(
&self,
id: &str,
version: &Version,
name: &str,
args: &[Variable],
) -> Result<O, CallFunctionDependError> {
let depend = self
.depends
.iter()
.find(|&depend| *depend == (id, version))
.ok_or(CallFunctionDependError::DependNotFound)?;
let plugin = self
.loader
.as_ref()
.get_plugin_by_bundle(depend)
.ok_or(CallFunctionDependError::DependNotFound)?;
Ok(plugin.call_function(name, args)?)
}
/// Calls a function on an optional dependency.
///
/// This method allows the current plugin to call functions exposed by its optional dependencies.
/// Unlike required dependencies, this method returns `None` if the dependency is not available.
///
/// # Parameters
///
/// * `id` - Optional dependency plugin ID
/// * `version` - Optional dependency plugin version
/// * `name` - Function name to call
/// * `args` - Arguments to pass to the function
///
/// # Returns
///
/// Returns `Result<Option<O>, PluginCallFunctionError>` containing:
/// - `Ok(Some(result))` if the dependency exists and the call succeeds
/// - `Ok(None)` if the dependency is not available
/// - `Err(error)` if the function call fails
///
/// # Note
///
/// This method only works with optional dependencies. For required dependencies,
/// use `call_function_depend`.
pub fn call_function_optional_depend(
&self,
id: &str,
version: &Version,
name: &str,
args: &[Variable],
) -> Result<Option<O>, PluginCallFunctionError> {
let depend = self
.optional_depends
.iter()
.find(|&depend| *depend == (id, version));
depend
.and_then(|depend| self.loader.as_ref().get_plugin_by_bundle(depend))
.map(|plugin| plugin.call_function(name, args))
.transpose()
}
}