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>
impl<'conn> PlanExecutor<'conn>
Sourcepub const fn new(conn: &'conn Connection) -> Self
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());Sourcepub const fn dry_run(self) -> Self
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();Sourcepub fn execute(&mut self, plan: &OperationPlan) -> Result<ExecutionResult>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more