PlanExecutor

Struct PlanExecutor 

Source
pub struct PlanExecutor<'conn> { /* private fields */ }
Expand description

Executes operation plans against the database.

The executor can run in normal mode (applying changes) or dry-run mode (validating without changes).

§Examples

use trop::operations::{PlanExecutor, ReservePlan, ReserveOptions};
use trop::{Database, DatabaseConfig, ReservationKey, Port};
use trop::config::ConfigBuilder;
use std::path::PathBuf;

let mut db = Database::open(DatabaseConfig::new("/tmp/trop.db")).unwrap();
let config = ConfigBuilder::new().build().unwrap();
let key = ReservationKey::new(PathBuf::from("/path"), None).unwrap();
let port = Port::try_from(8080).unwrap();

let options = ReserveOptions::new(key, Some(port))
    .with_allow_unrelated_path(true);
let plan = ReservePlan::new(options, &config).build_plan(db.connection()).unwrap();

// Normal execution
let mut executor = PlanExecutor::new(db.connection());
let result = executor.execute(&plan).unwrap();
assert!(result.success);

// Dry-run execution
let mut executor = PlanExecutor::new(db.connection()).dry_run();
let result = executor.execute(&plan).unwrap();
assert!(result.dry_run);

Implementations§

Source§

impl<'conn> PlanExecutor<'conn>

Source

pub const fn new(conn: &'conn Connection) -> Self

Creates a new plan executor.

§Examples
use trop::operations::PlanExecutor;
use trop::{Database, DatabaseConfig};

let mut db = Database::open(DatabaseConfig::new("/tmp/trop.db")).unwrap();
let executor = PlanExecutor::new(db.connection());
Source

pub const fn dry_run(self) -> Self

Sets the executor to dry-run mode.

In dry-run mode, the executor validates the plan but does not actually modify the database.

§Examples
use trop::operations::PlanExecutor;
use trop::{Database, DatabaseConfig};

let mut db = Database::open(DatabaseConfig::new("/tmp/trop.db")).unwrap();
let executor = PlanExecutor::new(db.connection()).dry_run();
Source

pub fn execute(&mut self, plan: &OperationPlan) -> Result<ExecutionResult>

Executes the given plan.

If in dry-run mode, validates the plan but makes no database changes. Otherwise, applies all actions in the plan to the database.

§Errors

Returns an error if any action fails to execute.

§Examples
use trop::operations::{PlanExecutor, OperationPlan};
use trop::{Database, DatabaseConfig};

let mut db = Database::open(DatabaseConfig::new("/tmp/trop.db")).unwrap();
let plan = OperationPlan::new("Test operation");

let mut executor = PlanExecutor::new(db.connection());
let result = executor.execute(&plan).unwrap();

Auto Trait Implementations§

§

impl<'conn> Freeze for PlanExecutor<'conn>

§

impl<'conn> !RefUnwindSafe for PlanExecutor<'conn>

§

impl<'conn> !Send for PlanExecutor<'conn>

§

impl<'conn> !Sync for PlanExecutor<'conn>

§

impl<'conn> Unpin for PlanExecutor<'conn>

§

impl<'conn> !UnwindSafe for PlanExecutor<'conn>

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, 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> ErasedDestructor for T
where T: 'static,