Skip to main content

Builder

Struct Builder 

Source
pub struct Builder<T, R, F, E>
where T: XyzArgs, R: XyzSchema + Serialize, F: Fn(&Ctx, &T) -> Result<R, E> + Send + Sync + 'static, E: Error + Send + Sync + 'static,
{ /* private fields */ }
Expand description

Builder 是一条定义链:当前命令内联配置,命令列表经 also 追加,run 注册 + 派发 + 退出。

Implementations§

Source§

impl<T, R, F, E> Builder<T, R, F, E>
where T: XyzArgs, R: XyzSchema + Serialize, F: Fn(&Ctx, &T) -> Result<R, E> + Send + Sync + 'static, E: Error + Send + Sync + 'static,

Source

pub fn summary(self, s: impl Into<String>) -> Self

单行描述。

Source

pub fn description(self, s: impl Into<String>) -> Self

长描述。

Source

pub fn cli(self, h: CliHints) -> Self

命令级 CLI 配置。

Source

pub fn http(self, h: HTTPHints) -> Self

命令级 HTTP 配置。

Source

pub fn mcp(self, h: MCPHints) -> Self

命令级 MCP 配置。

Source

pub fn configure(self, cfg: Config) -> Self

设置 Run/RunArgs 使用的派发器配置(模式词、通道能力)。在链任意 位置调用;run_args_config 为那次调用显式指定 Config。

Source

pub fn also(self, cmds: &[&dyn Definable]) -> Self

把当前命令与传入的每条命令都注册进同一默认注册表,然后续链。可 再次调用追加更多。注册失败终止链:在 run 处浮出。

Source

pub fn run(self) -> !

注册(若尚未注册)、按进程参数派发默认注册表、按结果退出。其后 的代码按设计不可达。

Source

pub fn run_config(self, cfg: Config) -> !

带自定义配置的 run。

Source

pub fn run_args(self, args: Vec<String>) -> i32

run 的可测试/可嵌入形态:注册、派发并返回退出码,不退出进程。 使用链上 configure 的配置(零值 = 全默认)。

Source

pub fn run_args_config(self, args: Vec<String>, cfg: Config) -> i32

带自定义配置的 run_args。

Trait Implementations§

Source§

impl<T, R, F, E> Definable for Builder<T, R, F, E>
where T: XyzArgs, R: XyzSchema + Serialize, F: Fn(&Ctx, &T) -> Result<R, E> + Send + Sync + 'static, E: Error + Send + Sync + 'static,

Source§

fn register(&self, reg: &Registry) -> Result<()>

Auto Trait Implementations§

§

impl<T, R, F, E> !RefUnwindSafe for Builder<T, R, F, E>

§

impl<T, R, F, E> !UnwindSafe for Builder<T, R, F, E>

§

impl<T, R, F, E> Freeze for Builder<T, R, F, E>
where Command<T, R, F, E>: Freeze,

§

impl<T, R, F, E> Send for Builder<T, R, F, E>
where Command<T, R, F, E>: Send,

§

impl<T, R, F, E> Sync for Builder<T, R, F, E>
where Command<T, R, F, E>: Sync,

§

impl<T, R, F, E> Unpin for Builder<T, R, F, E>
where Command<T, R, F, E>: Unpin,

§

impl<T, R, F, E> UnsafeUnpin for Builder<T, R, F, E>
where Command<T, R, F, E>: UnsafeUnpin,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more