1 //! The process boundary that residency needs to stop a plugin.2 //!3 //! Unload is process death. The core decides when a model leaves, but it must4 //! not know how a child is spawned: this trait is the seam between the two. A5 //! test counts stops through it; the web binary owns the supervisor behind it.6 7 use inf3r_supervisor::Failure;8 9 use crate::Served;10 11 /// Starts and stops the child of one plugin.12 pub trait Loader: Send + Sync {13 /// Stops the child. The caller releases the reservation after this returns,14 /// because a child that is gone stops writing to the device.15 fn stop(&self, plugin: &str) -> Result<(), String>;16 17 /// Starts the plugin and returns the peer that answered.18 fn start(&self, plugin: &str) -> Result<Served, String>;19 20 /// Reports a child that exited on its own and reaps it.21 ///22 /// A loader without a process has nothing to reap. The web's loader turns23 /// the exit status into the supervisor's failure class; the core decides24 /// what that class means for the peer and the ledger.25 fn exit(&self, _plugin: &str) -> Result<Option<Failure>, String> {26 Ok(None)27 }28 29 /// The class of the last `start` error for this plugin, when it had one.30 ///31 /// The trait returns the message for the operator; this is the machine32 /// classification that decides whether the next start is allowed.33 fn start_failure(&self, _plugin: &str) -> Option<Failure> {34 None35 }36 }37 38 /// The loader of a core that owns no process.39 ///40 /// A core without a supervisor must refuse to evict rather than pretend that it41 /// did. This loader is that refusal, and it is what `Core::new` installs.42 pub struct NoLoader;43 44 impl Loader for NoLoader {45 fn stop(&self, _plugin: &str) -> Result<(), String> {46 Err(NO_LOADER.to_string())47 }48 49 fn start(&self, _plugin: &str) -> Result<Served, String> {50 Err(NO_LOADER.to_string())51 }52 }53 54 /// The sentence for a caller that asked a core with no supervisor to swap.55 const NO_LOADER: &str = "no loader is installed";