Skip to main content

Bootloader

Struct Bootloader 

Source
pub struct Bootloader { /* private fields */ }
Expand description

A thin bootloader over LoadSession for a single-library product binary.

// `my-server ARGS...` boots exactly like `sim serve ARGS...`, dispatching the
// library's `cli/main/serve` entrypoint. No Cx::new in the binary.
let code = Bootloader::standard()
    .host_verb("serve", "lib/my-server", || Box::new(MyServeLib::new()))
    .run(std::iter::once("serve".into()).chain(std::env::args_os().skip(1)))?;
std::process::exit(code);

Implementations§

Source§

impl Bootloader

Source

pub fn standard() -> Self

The standard boot session: the in-process host loader only, matching the default sim binary. Add libraries with Bootloader::host_verb.

Source

pub fn host_verb<F>(self, verb: &str, name: &str, factory: F) -> Self
where F: Fn() -> Box<dyn Lib> + Send + Sync + 'static,

Registers a statically-linked library under name and makes it the default source for verb, so a bare <verb> ARGS... dispatches to the library’s cli/main/<verb> entrypoint with no explicit --load.

The library must be a LibTarget::HostRegistered lib that exports a cli/main/<verb> function (see crate::cli_main_entrypoint_symbol).

Source

pub fn host_lib<F>(self, name: &str, factory: F) -> Self
where F: Fn() -> Box<dyn Lib> + Send + Sync + 'static,

Registers a statically-linked library under name WITHOUT binding it to a verb – for a supporting library the served verb needs, most commonly the boot codec (register it under codec/<name> and pass --codec <name> so the boot resolves the host codec instead of the default).

Source

pub fn with_capability(self, capability: CapabilityName) -> Self

Grants a capability the served library requires (for example a transport or tool-call capability).

Source

pub fn with_context<F>(self, configure: F) -> Self
where F: FnOnce(&mut Cx),

Installs context-level runtime support into the boot Cx before dispatch (e.g. a codec, an eval policy, a supporting lib). Concrete serve behavior stays in the loaded library.

Source

pub fn run<I, S>(self, args: I) -> Result<i32, CliError>
where I: IntoIterator<Item = S>, S: Into<OsString>,

Boots the runtime, applies the registered libraries, and dispatches args (typically the process arguments). A blocking serve verb runs to completion here; its returned value becomes the process exit code.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.