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), ) -> 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.

Trait Implementations§

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 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 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> 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<'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, 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