Skip to main content

EmbeddedClient

Struct EmbeddedClient 

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

A client that wraps a Kernel directly for in-process access.

§Example

use kaish_client::EmbeddedClient;
use kaish_kernel::{Kernel, KernelConfig};

let kernel = Kernel::new(KernelConfig::transient())?;
let client = EmbeddedClient::new(kernel);

let result = client.execute("X=42").await?;
assert!(result.ok());

let value = client.get_var("X").await?;
assert_eq!(value, Some(Value::Int(42)));

Implementations§

Source§

impl EmbeddedClient

Source

pub fn new(kernel: Kernel) -> Self

Create a new embedded client wrapping the given kernel.

Source

pub fn transient() -> ClientResult<Self>

Create a new embedded client with a transient (non-persistent) kernel.

Source

pub fn with_defaults() -> ClientResult<Self>

Create a new embedded client with default configuration.

Source

pub fn kernel(&self) -> &Kernel

Get a reference to the underlying kernel.

Source

pub async fn execute_streaming( &self, input: &str, on_output: &mut (dyn FnMut(&ExecResult) + Send), ) -> ClientResult<ExecResult>

Execute with a per-statement output callback.

Each statement’s result is passed to on_output as it completes. External commands in interactive mode already stream via Stdio::inherit(); this callback handles builtins and other captured output.

Source

pub async fn execute_with_options( &self, input: &str, opts: ExecuteOptions, ) -> ClientResult<ExecResult>

Execute with full per-call options (timeout, cancel token, vars overlay, cwd override). Use Self::execute_with_options_streaming for the per-statement callback variant.

Source

pub async fn execute_with_options_streaming( &self, input: &str, opts: ExecuteOptions, on_output: &mut (dyn FnMut(&ExecResult) + Send), ) -> ClientResult<ExecResult>

Execute with options + per-statement output callback.

Trait Implementations§

Source§

impl Clone for EmbeddedClient

Source§

fn clone(&self) -> EmbeddedClient

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 KernelClient for EmbeddedClient

Source§

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, input: &'life1 str, ) -> Pin<Box<dyn Future<Output = ClientResult<ExecResult>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute kaish source code. Read more
Source§

fn execute_with_vars<'life0, 'life1, 'async_trait>( &'life0 self, input: &'life1 str, vars: HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = ClientResult<ExecResult>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute kaish source code with a transient overlay of exported variables. Read more
Source§

fn get_var<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = ClientResult<Option<Value>>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a variable value.
Source§

fn set_var<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, value: Value, ) -> Pin<Box<dyn Future<Output = ClientResult<()>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Set a variable value.
Source§

fn list_vars<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ClientResult<Vec<(String, Value)>>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all variables.
Source§

fn tool_schemas<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ClientResult<Vec<ToolSchema>>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List the schemas of all available tools (builtins + registered tools). Read more
Source§

fn has_function<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = ClientResult<bool>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Report whether a user-defined function with the given name exists. Read more
Source§

fn cancel<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ClientResult<()>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Cancel the kernel’s in-flight execution. Read more
Source§

fn cwd<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ClientResult<String>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the current working directory.
Source§

fn set_cwd<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = ClientResult<()>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Set the current working directory.
Source§

fn last_result<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ClientResult<ExecResult>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the last execution result ($?).
Source§

fn reset<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ClientResult<()>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reset the kernel to initial state.
Source§

fn ping<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ClientResult<String>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Ping the kernel (health check).
Source§

fn shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ClientResult<()>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Shutdown the kernel.
Source§

fn read_blob<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ClientResult<Vec<u8>>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read a blob by ID. Read more
Source§

fn write_blob<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, content_type: &'life1 str, data: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = ClientResult<String>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Write a blob and return its ID. Read more
Source§

fn delete_blob<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ClientResult<bool>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a blob by ID. Read more

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,

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

Source§

type Output = T

Should always be Self
Source§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

Source§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
Source§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
Source§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
Source§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
Source§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a MaybeRef.
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 = 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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