Instance Control
Overview
InstanceControl Trait
use lighty_launch::InstanceControl; // Required!
// Now you can use instance management methods
if let Some(pid) = instance.get_pid() {
println!("Running: {}", pid);
}Trait Definition
pub trait InstanceControl: VersionInfo {
/// Get the first PID for this instance
fn get_pid(&self) -> Option<u32>;
/// Get all PIDs for this instance (supports multiple processes)
fn get_pids(&self) -> Vec<u32>;
/// Close an instance by PID
async fn close_instance(&self, pid: u32) -> InstanceResult<()>;
/// Delete an instance completely (must not be running)
async fn delete_instance(&self) -> InstanceResult<()>;
/// Calculate the size of an instance
fn size_of_instance(&self, version: &Version) -> InstanceSize;
}Instance Lifecycle
Instance Manager
Internal Structure
Registration
Unregistration
Process Management
Get PID
Get All PIDs
Close Instance
Windows
Linux/macOS
Delete Instance
Console Streaming
Console Handler
Stdout Streaming
Stderr Streaming
Console Events
Instance Size
InstanceSize Structure
Events
Instance Lifecycle Events
Listening to Events
Complete Examples
Basic Instance Management
Multiple Instance Tracking
Console Monitoring
Instance Size Calculation
Error Handling
InstanceError Types
Error Examples
Best Practices
1. Always Import the Trait
2. Check Before Closing
3. Close Before Deleting
4. Monitor Console with Events
5. Handle Errors Gracefully
Related Documentation
Last updated