Struct App

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

Main application structure with dependency injection support.

The App struct provides a programmatic interface to SubX functionality, designed for embedding SubX in other Rust applications or for advanced use cases requiring fine-grained control over configuration and execution.

§Use Cases

  • Embedding: Use SubX as a library component in larger applications
  • Testing: Programmatic testing of SubX functionality with custom configurations
  • Automation: Scripted execution of SubX operations without shell commands
  • Custom Workflows: Building complex workflows that combine multiple SubX operations

§vs CLI Interface

FeatureCLI (subx command)App (Library API)
UsageCommand line toolEmbedded in Rust code
ConfigFiles + EnvironmentProgrammatic injection
OutputTerminal/stdoutProgrammatic control
Error HandlingExit codesResult types

§Examples

§Basic Usage

use subx_cli::{App, config::ProductionConfigService};
use std::sync::Arc;

let config_service = Arc::new(ProductionConfigService::new()?);
let app = App::new(config_service);

// Execute operations programmatically
app.match_files("/movies", true).await?; // dry run
app.convert_files("/subs", "srt", Some("/output")).await?;

§With Custom Configuration

use subx_cli::{App, config::{TestConfigService, Config}};
use std::sync::Arc;

let mut config_service = TestConfigService::with_ai_settings("openai", "gpt-4");

let app = App::new(Arc::new(config_service));
app.match_files("/path", false).await?;

Implementations§

Source§

impl App

Source

pub fn new(config_service: Arc<dyn ConfigService>) -> Self

Create a new application instance with the provided configuration service.

§Arguments
  • config_service - The configuration service to use
§Examples
use subx_cli::{App, config::TestConfigService};
use std::sync::Arc;

let config_service = Arc::new(TestConfigService::with_defaults());
let app = App::new(config_service);
Source

pub fn new_with_production_config() -> Result<Self>

Create a new application instance with the production configuration service.

This is the default way to create an application instance for production use.

§Examples
use subx_cli::App;

let app = App::new_with_production_config()?;
// Ready to use with production configuration
§Errors

Returns an error if the production configuration service cannot be created.

Source

pub async fn run(&self) -> Result<()>

Run the application with command-line argument parsing.

This method provides a programmatic way to run SubX with CLI-style arguments, useful for embedding SubX in other Rust applications.

§Examples
use subx_cli::{App, config::ProductionConfigService};
use std::sync::Arc;

let config_service = Arc::new(ProductionConfigService::new()?);
let app = App::new(config_service);

// This parses std::env::args() just like the CLI
app.run().await?;
§Errors

Returns an error if command execution fails.

Source

pub async fn handle_command(&self, command: Commands) -> Result<()>

Handle a specific command with the current configuration.

This method allows programmatic execution of specific SubX commands without parsing command-line arguments.

§Examples
use subx_cli::{App, cli::{Commands, MatchArgs}, config::TestConfigService};
use std::sync::Arc;

let config_service = Arc::new(TestConfigService::with_defaults());
let app = App::new(config_service);

let match_args = MatchArgs {
    path: Some("/path/to/files".into()),
    input_paths: vec![],
    dry_run: true,
    confidence: 80,
    recursive: false,
    backup: false,
    copy: false,
    move_files: false,
};

app.handle_command(Commands::Match(match_args)).await?;
§Arguments
  • command - The command to execute
§Errors

Returns an error if command execution fails.

Source

pub async fn match_files(&self, input_path: &str, dry_run: bool) -> Result<()>

Execute a match operation programmatically.

This is a convenience method for programmatic usage without needing to construct the Commands enum manually.

§Examples
use subx_cli::{App, config::TestConfigService};
use std::sync::Arc;

let config_service = Arc::new(TestConfigService::with_defaults());
let app = App::new(config_service);

// Match files programmatically
app.match_files("/path/to/files", true).await?; // dry_run = true
§Arguments
  • input_path - Path to the directory or file to process
  • dry_run - Whether to perform a dry run (no actual changes)
§Errors

Returns an error if the match operation fails.

Source

pub async fn convert_files( &self, input_path: &str, output_format: &str, output_path: Option<&str>, ) -> Result<()>

Convert subtitle files programmatically.

§Examples
use subx_cli::{App, config::TestConfigService};
use std::sync::Arc;

let config_service = Arc::new(TestConfigService::with_defaults());
let app = App::new(config_service);

// Convert to SRT format
app.convert_files("/path/to/subtitles", "srt", Some("/output/path")).await?;
§Arguments
  • input_path - Path to subtitle files to convert
  • output_format - Target format (“srt”, “ass”, “vtt”, etc.)
  • output_path - Optional output directory path
§Errors

Returns an error if the conversion fails.

Source

pub async fn sync_files( &self, video_path: &str, subtitle_path: &str, method: &str, ) -> Result<()>

Synchronize subtitle files programmatically.

§Examples
use subx_cli::{App, config::TestConfigService};
use std::sync::Arc;

let config_service = Arc::new(TestConfigService::with_defaults());
let app = App::new(config_service);

// Synchronize using VAD method
app.sync_files("/path/to/video.mp4", "/path/to/subtitle.srt", "vad").await?;
§Arguments
  • video_path - Path to video file for audio analysis
  • subtitle_path - Path to subtitle file to synchronize
  • method - Synchronization method (“vad”, “manual”)
§Errors

Returns an error if synchronization fails.

Source

pub async fn sync_files_with_offset( &self, subtitle_path: &str, offset: f32, ) -> Result<()>

Synchronize subtitle files with manual offset.

§Examples
use subx_cli::{App, config::TestConfigService};
use std::sync::Arc;

let config_service = Arc::new(TestConfigService::with_defaults());
let app = App::new(config_service);

// Apply +2.5 second offset to subtitles
app.sync_files_with_offset("/path/to/subtitle.srt", 2.5).await?;
§Arguments
  • subtitle_path - Path to subtitle file to synchronize
  • offset - Time offset in seconds (positive delays, negative advances)
§Errors

Returns an error if synchronization fails.

Source

pub fn config_service(&self) -> &Arc<dyn ConfigService>

Get a reference to the configuration service.

This allows access to the configuration service for testing or advanced use cases.

Source

pub fn get_config(&self) -> Result<Config>

Get the current configuration.

This is a convenience method that retrieves the configuration from the configured service.

§Errors

Returns an error if configuration loading fails.

Auto Trait Implementations§

§

impl Freeze for App

§

impl !RefUnwindSafe for App

§

impl Send for App

§

impl Sync for App

§

impl Unpin for App

§

impl !UnwindSafe for App

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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.
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,