Skip to main content

ParamResolver

Struct ParamResolver 

Source
pub struct ParamResolver<'a> { /* private fields */ }
Expand description

Action パラメータ解決ヘルパー

Environment がアクションパラメータを取得する際の共通パターンを提供する。 args[key]target の優先順位を統一し、空文字列の扱いを正規化する。

§Example

fn handle_read_logs(&self, action: &Action) -> WorkResult {
    let resolver = ParamResolver::new(action);

    // 必須パラメータ: なければエラー
    let service = match resolver.require("service") {
        Ok(s) => s,
        Err(e) => return WorkResult::env_failure(e.to_string()),
    };

    // オプショナルパラメータ
    let limit = resolver.get("limit");

    // ...
}

Implementations§

Source§

impl<'a> ParamResolver<'a>

Source

pub fn new(action: &'a Action) -> Self

新しい ParamResolver を作成

Source

pub fn get(&self, key: &str) -> Option<&str>

パラメータを取得(args[key] を優先、なければ target をフォールバック)

空文字列は None として扱う。

§Arguments
  • key - パラメータ名(例: “service”, “path”)
§Returns
  • Some(&str): 値が存在し、空でない場合
  • None: 値が存在しないか、空文字列の場合
Source

pub fn require(&self, key: &str) -> Result<&str, ActionValidationError>

必須パラメータを取得(なければエラー)

§Arguments
  • key - パラメータ名
§Returns
  • Ok(&str): 値が存在する場合
  • Err(ActionValidationError::MissingParam): 値が存在しない場合
Source

pub fn get_target_first(&self, key: &str) -> Option<&str>

target を優先して取得(なければ args[key] をフォールバック)

LLM が target フィールドにパラメータを入れる場合に使用。

§Arguments
  • key - フォールバック用のパラメータ名
Source

pub fn require_target_first( &self, key: &str, ) -> Result<&str, ActionValidationError>

target を優先して必須パラメータを取得

Source

pub fn target(&self) -> Option<&str>

target のみを取得(args は参照しない)

Source

pub fn arg(&self, key: &str) -> Option<&str>

指定した key の args のみを取得(target は参照しない)

Source

pub fn action_name(&self) -> &str

Action 名を取得

Source

pub fn action(&self) -> &Action

元の Action への参照を取得

Trait Implementations§

Source§

impl<'a> Debug for ParamResolver<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ParamResolver<'a>

§

impl<'a> RefUnwindSafe for ParamResolver<'a>

§

impl<'a> Send for ParamResolver<'a>

§

impl<'a> Sync for ParamResolver<'a>

§

impl<'a> Unpin for ParamResolver<'a>

§

impl<'a> UnwindSafe for ParamResolver<'a>

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
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