Skip to main content

RuntimeConfigBuilder

Struct RuntimeConfigBuilder 

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

Consuming builder for an immutable runtime configuration.

§Examples

use tenferro_runtime::RuntimeConfigBuilder;

let runtime = RuntimeConfigBuilder::new().build()?;
assert_eq!(runtime.snapshot()?.engine_count(), 0);

Implementations§

Source§

impl RuntimeConfigBuilder

Source

pub fn new() -> Self

Create an empty runtime builder.

Source

pub fn execution_policy(&mut self, value: ExecutionPolicy) -> &mut Self

Replace the execution policy in the candidate configuration.

Source

pub fn register_engine( &mut self, value: EngineRegistration, ) -> Result<&mut Self, RuntimeConfigError>

Register a new engine candidate.

§Errors

Returns RuntimeConfigError::DuplicateEngine if a different candidate with the same engine ID is already present.

Source

pub fn replace_engine( &mut self, value: EngineRegistration, ) -> Result<&mut Self, RuntimeConfigError>

Explicitly replace an existing engine candidate.

§Errors

Returns RuntimeConfigError::MissingEngine if the engine ID is absent.

Source

pub fn remove_engine( &mut self, id: &EngineId, ) -> Result<&mut Self, RuntimeConfigError>

Remove an existing engine candidate.

§Errors

Returns RuntimeConfigError::MissingEngine if the engine ID is absent.

Source

pub fn install_extension_module( &mut self, value: Arc<dyn ExtensionModule>, ) -> Result<&mut Self, RuntimeConfigError>

Install an extension module transaction.

§Errors

Returns RuntimeConfigError::ExtensionModule when module configuration fails or a distinct module already uses the same module ID.

Source

pub fn register_transfer_provider( &mut self, source: TransferEndpoint, destination: TransferEndpoint, provider: Arc<dyn TransferProvider>, ) -> Result<&mut Self, RuntimeConfigError>

Register a transfer provider keyed by source and destination endpoints.

§Examples
use std::sync::Arc;
use tenferro_runtime::{
    assemble_preparation_only_engine_registration, CoreCapabilityBundle, EngineId,
    EngineRegistration, EngineRegistrationMetadata, Error, ExecutionContextIdentity,
    HardwareClassId, PreparationOnlyEngineRegistrationConfig, ProviderDeviceIdentity,
    ProviderId, Runtime, StorageClass, TransferEndpoint, TransferProvider, TransferRequest,
};

#[derive(Debug)]
struct ExampleProvider;

impl TransferProvider for ExampleProvider {
    fn transfer_blocking(
        &self,
        _request: TransferRequest<'_>,
    ) -> tenferro_runtime::Result<tenferro_tensor::Tensor> {
        Err(Error::Internal("the example does not execute a transfer".into()))
    }
}

fn registration(
    id: EngineId,
    target: &str,
    storage: &StorageClass,
) -> Result<EngineRegistration, tenferro_runtime::RuntimeConfigError> {
    let metadata = EngineRegistrationMetadata::new(
        id,
        ProviderDeviceIdentity::new(ProviderId::new("example.provider")?, target)?,
        HardwareClassId::new("example.hardware")?,
        Arc::from([storage.clone()]),
        storage.clone(),
        CoreCapabilityBundle::default(),
    );
    assemble_preparation_only_engine_registration(
        PreparationOnlyEngineRegistrationConfig::new(
            metadata,
            ExecutionContextIdentity::of::<()>(),
        ),
    )
}

let storage = StorageClass::new("example.storage.host")?;
let source_id = EngineId::new("example.engine.source")?;
let destination_id = EngineId::new("example.engine.destination")?;
let source = registration(
    source_id.clone(),
    "source-0",
    &storage,
)?;
let destination = registration(
    destination_id.clone(),
    "destination-0",
    &storage,
)?;
let mut builder = Runtime::builder();
builder.register_engine(source)?;
builder.register_engine(destination)?;
builder.register_transfer_provider(
    TransferEndpoint::new(source_id, storage.clone()),
    TransferEndpoint::new(destination_id, storage),
    Arc::new(ExampleProvider),
)?;
let runtime = builder.build()?;
assert_eq!(runtime.snapshot()?.transfer_provider_count(), 1);
§Errors

Returns RuntimeConfigError::ConflictingRegistration if a different provider is already registered for the same endpoint pair. The complete endpoint pair is validated when Self::build freezes the candidate.

Source

pub fn remove_transfer_provider( &mut self, source: TransferEndpoint, destination: TransferEndpoint, ) -> Result<&mut Self, RuntimeConfigError>

Remove the transfer provider for an endpoint pair.

This explicit removal is required before changing an engine’s physical binding. The route can then be registered again against the replacement binding in the same candidate transaction.

§Errors

Returns RuntimeConfigError::MissingTransferProvider when the exact endpoint pair is not registered.

Source

pub fn replace_extension_module( &mut self, value: Arc<dyn ExtensionModule>, ) -> Result<&mut Self, RuntimeConfigError>

Replace an extension module transaction, installing it when absent.

§Errors

Returns RuntimeConfigError::ExtensionModule when module configuration fails.

Source

pub fn remove_extension_module( &mut self, id: &ExtensionModuleId, ) -> Result<&mut Self, RuntimeConfigError>

Remove an extension module candidate if present.

§Errors

This method currently has no failing absent-module path; it returns RuntimeConfigError only for future validated module removal failures.

Source

pub fn build(self) -> Result<Runtime, RuntimeConfigError>

Build and publish the initial runtime snapshot.

§Errors

Returns RuntimeConfigError::IdentityExhausted if runtime or registration identity allocation would wrap, or RuntimeConfigError::UnknownTransferEndpointEngine or RuntimeConfigError::UnsupportedTransferEndpointStorage if a registered transfer endpoint is invalid for the complete candidate.

Trait Implementations§

Source§

impl Debug for RuntimeConfigBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for RuntimeConfigBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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, 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,