Skip to main content

Context

Struct Context 

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

What a method knows about the call it answers.

Implementations§

Source§

impl Context

Source

pub fn try_new( key: CallKey, spec: &TypeSpec, generic: Option<&CallTypes>, cancelled: Cancellation, ) -> Result<Context, DecodeError>

The context of the call key names to the declaration spec describes, with generic’s views for a generic one, validated completely before the author’s code sees it. Its log lines go nowhere.

§Errors

Refuses views that do not fit spec: views given to a nongeneric declaration, missing from a generic one, or describing types the declaration does not admit.

Source

pub fn types(&self) -> Option<&ValidatedTypes>

The admitted concrete type description, if this Tool is generic.

Source

pub fn for_test(key: CallKey) -> Context

The context of a call made by a test rather than a host: the call key names, of a nongeneric Tool, not cancelled. Context::cancel makes it one that withdraws its call.

Source

pub fn run(&self) -> &RunId

The run’s id.

Source

pub fn call(&self) -> &CallRef

The call’s id, which a call sent again after a crash keeps.

Source

pub fn key(&self) -> CallKey

The call’s key, its run’s id and its own together: the address a Tool hands the outside world as an idempotency key or a callback address, and that reply answers.

Source

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

For a call to a Tool with exactly one type parameter, the canonical text of the JSON Schema of the concrete type the call binds to it, made from the call’s types: what a model’s structured output, or any other outside producer, is asked to fit. None for a nongeneric call and for one whose Tool has several type parameters.

Source

pub fn decode<T: Shaped>(&self, data: &str) -> Result<T, DecodeError>

Reads JSON text data, such as a model’s output, as a value of the concrete type the call binds to its one type parameter, by the rules of Decoding (abi.md), and gives it as T, the Rust type the Tool writes for it: Encoded for the type parameter itself.

§Errors

Refuses data that is not JSON of a value of that type, saying why: the author turns the error into a value of the Tool’s declared result. Refused too for a nongeneric call, and for one whose Tool has several type parameters.

Source

pub fn to_json<T: Shaped>(&self, value: &T) -> Result<String, DecodeError>

The canonical text of value’s JSON form (abi.md, The JSON form) at the concrete type the call binds to its one type parameter, as its CallTypes gives it: what a Tool hands a model.

§Errors

Refuses a value that is not one of that type, and a call that does not bind exactly one type parameter.

Source

pub fn log(&self, level: Level, message: &str)

Writes one line to the run’s log at level, as a log frame naming the call’s run and call. A call a test makes logs nowhere.

Source

pub fn cancelled(&self) -> bool

Whether the host asked to stop work on this call, or withdrew it: a held call that was closed is sent once more with this set, so the author can withdraw the question it asked, and whatever it answers is dropped. It proves nothing either way.

Source

pub fn cancel(&self)

Asks to stop work on this call, as a cancel does.

Source

pub fn cancellation(&self) -> Cancellation

The call’s cancellation, which work that blocks can wait on beside whatever else it waits for, instead of asking Context::cancelled again and again.

Source§

impl Context

Source

pub fn resource<T: Send + Sync + 'static>(&self) -> Option<Arc<T>>

Retrieves the initialized process resource by its actual Rust type.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Context

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Context

§

impl Freeze for Context
where *const u8 is !null: Freeze, PhantomData<NonZero<u64>>: Freeze, NonZero<u64>: Freeze, *const ArcInner<CancelState> is !null: Freeze, PhantomData<ArcInner<CancelState>>: Freeze, *const ArcInner<ValidatedTypes> is !null: Freeze, PhantomData<ArcInner<ValidatedTypes>>: Freeze, *const ArcInner<Mutex<Output>> is !null: Freeze, PhantomData<ArcInner<Mutex<Output>>>: Freeze,

§

impl Move for Context

§

impl RefUnwindSafe for Context

§

impl Send for Context
where RawVecInner: Send, NonZero<u64>: Send, Arc<CancelState>: Send, Arc<ValidatedTypes>: Send, Arc<Mutex<Output>>: Send,

§

impl Sync for Context
where RawVecInner: Sync, NonZero<u64>: Sync, Arc<CancelState>: Sync, Arc<ValidatedTypes>: Sync, Arc<Mutex<Output>>: Sync,

§

impl Unpin for Context
where *const u8 is !null: Unpin, NonZero<u64>: Unpin, Arc<CancelState>: Unpin, Arc<ValidatedTypes>: Unpin, Arc<Mutex<Output>>: Unpin,

§

impl UnsafeUnpin for Context
where *const u8 is !null: UnsafeUnpin, PhantomData<NonZero<u64>>: UnsafeUnpin, NonZeroU64Inner: UnsafeUnpin, *const ArcInner<CancelState> is !null: UnsafeUnpin, PhantomData<ArcInner<CancelState>>: UnsafeUnpin, *const ArcInner<ValidatedTypes> is !null: UnsafeUnpin, PhantomData<ArcInner<ValidatedTypes>>: UnsafeUnpin, *const ArcInner<Mutex<Output>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Output>>>: UnsafeUnpin,

§

impl UnwindSafe for Context
where RawVecInner: UnwindSafe, NonZero<u64>: UnwindSafe, Arc<CancelState>: UnwindSafe, Arc<ValidatedTypes>: UnwindSafe, Arc<Mutex<Output>>: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.