AirServiceProvider

Struct AirServiceProvider 

Source
pub struct AirServiceProvider {
    client: Arc<AirClient>,
}
Expand description

AirServiceProvider provides a high-level, convenient interface to the Air daemon service.

This provider wraps the AirClient and provides simplified methods with automatic request ID generation and error handling. It acts as a facade pattern, hiding the complexity of gRPC communication from the rest of the Mountain application.

§Example

use Mountain::Air::AirServiceProvider::{AirServiceProvider, DEFAULT_AIR_SERVER_ADDRESS};
use CommonLibrary::Error::CommonError::CommonError;

# #[tokio::main]
# async fn main() -> Result<(), CommonError> {
let provider = AirServiceProvider::new(DEFAULT_AIR_SERVER_ADDRESS.to_string()).await?;

// Check for health
let is_healthy = provider.health_check().await?;
println!("Air service healthy: {}", is_healthy);

// Check for updates
if let Some(update) =
	provider.check_for_updates("1.0.0".to_string(), "stable".to_string()).await?
{
	println!("Update available: {}", update.version);
}

# Ok(())
# }

Fields§

§client: Arc<AirClient>

The underlying Air client wrapped in Arc for thread safety

Implementations§

Source§

impl AirServiceProvider

Source

pub async fn new(address: String) -> Result<Self, CommonError>

Creates a new AirServiceProvider and connects to the Air daemon.

§Arguments
  • address - The gRPC server address (defaults to [::1]:50053)
§Returns
  • Ok(Self) - Successfully created provider
  • Err(CommonError) - Connection failure
§Example
use Mountain::Air::AirServiceProvider::AirServiceProvider;
use CommonLibrary::Error::CommonError::CommonError;

# #[tokio::main]
# async fn main() -> Result<(), CommonError> {
let provider = AirServiceProvider::new("http://[::1]:50053".to_string()).await?;
# Ok(())
# }
Source

pub async fn new_default() -> Result<Self, CommonError>

Creates a new AirServiceProvider with the default address.

This is a convenience method that uses DEFAULT_AIR_SERVER_ADDRESS.

§Returns
  • Ok(Self) - Successfully created provider
  • Err(CommonError) - Connection failure
§Example
use Mountain::Air::AirServiceProvider::AirServiceProvider;
use CommonLibrary::Error::CommonError::CommonError;

# #[tokio::main]
# async fn main() -> Result<(), CommonError> {
let provider = AirServiceProvider::new_default().await?;
# Ok(())
# }
Source

pub fn from_client(client: Arc<AirClient>) -> Self

Creates a new AirServiceProvider from an existing AirClient.

This is useful when you need to share a client or have special connection requirements.

§Arguments
  • client - The AirClient to wrap
§Returns
  • Self - The new provider
Source

pub fn client(&self) -> &Arc<AirClient>

Gets a reference to the underlying AirClient.

This provides access to the low-level client when needed.

§Returns

Reference to the AirClient

Source

pub fn is_connected(&self) -> bool

Checks if the provider is connected to Air.

§Returns
  • true - Connected
  • false - Not connected
Source

pub fn address(&self) -> &str

Gets the address of the Air daemon.

§Returns

The address string

Source

pub async fn authenticate( &self, username: String, password: String, provider: String, ) -> Result<String, CommonError>

Authenticates a user with the Air daemon.

This method handles request ID generation and provides a simplified interface for authentication.

§Arguments
  • username - User’s username
  • password - User’s password
  • provider - Authentication provider (e.g., “github”, “gitlab”, “microsoft”)
§Returns
  • Ok(token) - Authentication token if successful
  • Err(CommonError) - Authentication error
§Example
# use Mountain::Air::AirServiceProvider::AirServiceProvider;
# use CommonLibrary::Error::CommonError::CommonError;
# #[tokio::main]
# async fn main() -> Result<(), CommonError> {
# let provider = AirServiceProvider::new_default().await?;
let token = provider
	.authenticate("[email protected]".to_string(), "password".to_string(), "github".to_string())
	.await?;
println!("Auth token: {}", token);
# Ok(())
# }
Source

pub async fn check_for_updates( &self, current_version: String, channel: String, ) -> Result<Option<UpdateInfo>, CommonError>

Checks for available updates.

Returns None if no update is available, Some with update info otherwise.

§Arguments
  • current_version - Current application version
  • channel - Update channel (e.g., “stable”, “beta”, “nightly”)
§Returns
  • Ok(Some(update)) - Update available with information
  • Ok(None) - No update available
  • Err(CommonError) - Check error
§Example
# use Mountain::Air::AirServiceProvider::AirServiceProvider;
# use CommonLibrary::Error::CommonError::CommonError;
# #[tokio::main]
# async fn main() -> Result<(), CommonError> {
# let provider = AirServiceProvider::new_default().await?;
if let Some(update) =
	provider.check_for_updates("1.0.0".to_string(), "stable".to_string()).await?
{
	println!("Update available: version {}", update.version);
}
# Ok(())
# }
Source

pub async fn download_update( &self, url: String, destination_path: String, checksum: String, ) -> Result<FileInfo, CommonError>

Downloads an update package.

§Arguments
  • url - URL of the update package
  • destination_path - Local path to save the downloaded file
  • checksum - Optional SHA256 checksum for verification
§Returns
  • Ok(file_info) - Downloaded file information
  • Err(CommonError) - Download error
Source

pub async fn apply_update( &self, version: String, update_path: String, ) -> Result<(), CommonError>

Applies an update package.

§Arguments
  • version - Version of the update
  • update_path - Path to the update package
§Returns
  • Ok(()) - Update applied successfully
  • Err(CommonError) - Application error
Source

pub async fn download_file( &self, url: String, destination_path: String, checksum: String, ) -> Result<FileInfo, CommonError>

Downloads a file.

§Arguments
  • url - URL of the file to download
  • destination_path - Local path to save the downloaded file
  • checksum - Optional SHA256 checksum for verification
§Returns
  • Ok(file_info) - Downloaded file information
  • Err(CommonError) - Download error
Source

pub async fn download_stream( &self, url: String, headers: HashMap<String, String>, ) -> Result<DownloadStream, CommonError>

Downloads a file as a stream.

This method initiates a streaming download from the given URL, returning a stream of chunks that can be processed incrementally without loading the entire file into memory.

§Arguments
  • url - URL of the file to download
  • headers - Optional HTTP headers
§Returns
  • Ok(stream) - Stream that yields download chunks
  • Err(CommonError) - Download error
§Example
# use Mountain::Air::AirServiceProvider::AirServiceProvider;
# use CommonLibrary::Error::CommonError::CommonError;
# #[tokio::main]
# async fn main() -> Result<(), CommonError> {
# let provider = AirServiceProvider::new_default().await?;
let mut stream = provider
	.download_stream(
		"https://example.com/large-file.zip".to_string(),
		std::collections::HashMap::new(),
	)
	.await?;

let mut buffer = Vec::new();
while let Some(chunk) = stream.next().await {
	let chunk = chunk?;
	buffer.extend_from_slice(&chunk.data);
	println!("Downloaded: {} / {} bytes", chunk.downloaded, chunk.total_size);
	if chunk.completed {
		break;
	}
}
# Ok(())
# }
Source

pub async fn index_files( &self, path: String, patterns: Vec<String>, exclude_patterns: Vec<String>, max_depth: u32, ) -> Result<IndexInfo, CommonError>

Indexes files in a directory.

§Arguments
  • path - Path to the directory to index
  • patterns - File patterns to include (e.g., [“.rs”, “.ts”])
  • exclude_patterns - File patterns to exclude (e.g., [“node_modules/*”])
  • max_depth - Maximum depth for recursion (0 for unlimited)
§Returns
  • Ok(index_info) - Index information with file count and total size
  • Err(CommonError) - Indexing error
§Example
# use Mountain::Air::AirServiceProvider::AirServiceProvider;
# use CommonLibrary::Error::CommonError::CommonError;
# #[tokio::main]
# async fn main() -> Result<(), CommonError> {
# let provider = AirServiceProvider::new_default().await?;
let info = provider
	.index_files(
		"/path/to/project".to_string(),
		vec!["*.rs".to_string(), "*.ts".to_string()],
		vec!["node_modules/*".to_string()],
		10,
	)
	.await?;
println!("Indexed {} files ({} bytes)", info.files_indexed, info.total_size);
# Ok(())
# }
Source

pub async fn search_files( &self, query: String, path: String, max_results: u32, ) -> Result<Vec<FileResult>, CommonError>

Searches for files matching a query.

§Arguments
  • query - Search query string
  • path - Path to search in (empty for entire workspace)
  • max_results - Maximum number of results to return (0 for unlimited)
§Returns
  • Ok(results) - Vector of file search results
  • Err(CommonError) - Search error
§Example
# use Mountain::Air::AirServiceProvider::AirServiceProvider;
# use CommonLibrary::Error::CommonError::CommonError;
# #[tokio::main]
# async fn main() -> Result<(), CommonError> {
# let provider = AirServiceProvider::new_default().await?;
let results = provider
	.search_files("fn main".to_string(), "/path/to/project".to_string(), 50)
	.await?;
for result in results {
	println!("Found: {} at line {}", result.path, result.line_number);
}
# Ok(())
# }
Source

pub async fn get_file_info( &self, path: String, ) -> Result<ExtendedFileInfo, CommonError>

Gets file information.

§Arguments
  • path - Path to the file
§Returns
  • Ok(file_info) - Extended file information
  • Err(CommonError) - Request error
Source

pub async fn get_status(&self) -> Result<AirStatus, CommonError>

Gets the status of the Air daemon.

§Returns
  • Ok(status) - Air daemon status information
  • Err(CommonError) - Request error
Source

pub async fn health_check(&self) -> Result<bool, CommonError>

Performs a health check on the Air daemon.

§Returns
  • Ok(healthy) - Health status (true if healthy)
  • Err(CommonError) - Check error
§Example
# use Mountain::Air::AirServiceProvider::AirServiceProvider;
# use CommonLibrary::Error::CommonError::CommonError;
# #[tokio::main]
# async fn main() -> Result<(), CommonError> {
# let provider = AirServiceProvider::new_default().await?;
if provider.health_check().await? {
	println!("Air service is healthy");
}
# Ok(())
# }
Source

pub async fn get_metrics( &self, metric_type: Option<String>, ) -> Result<AirMetrics, CommonError>

Gets metrics from the Air daemon.

§Arguments
  • metric_type - Optional type of metrics (e.g., “performance”, “resources”)
§Returns
  • Ok(metrics) - Metrics data
  • Err(CommonError) - Request error
Source

pub async fn get_resource_usage(&self) -> Result<ResourceUsage, CommonError>

Gets resource usage information.

§Returns
  • Ok(usage) - Resource usage data
  • Err(CommonError) - Request error
Source

pub async fn set_resource_limits( &self, memory_limit_mb: u32, cpu_limit_percent: u32, disk_limit_mb: u32, ) -> Result<(), CommonError>

Sets resource limits.

§Arguments
  • memory_limit_mb - Memory limit in MB
  • cpu_limit_percent - CPU limit as percentage (0-100)
  • disk_limit_mb - Disk limit in MB
§Returns
  • Ok(()) - Limits set successfully
  • Err(CommonError) - Set error
Source

pub async fn get_configuration( &self, section: String, ) -> Result<HashMap<String, String>, CommonError>

Gets configuration.

§Arguments
  • section - Configuration section (e.g., “grpc”, “authentication”, “updates”)
§Returns
  • Ok(config) - Configuration data as key-value pairs
  • Err(CommonError) - Request error
§Example
# use Mountain::Air::AirServiceProvider::AirServiceProvider;
# use CommonLibrary::Error::CommonError::CommonError;
# #[tokio::main]
# async fn main() -> Result<(), CommonError> {
# let provider = AirServiceProvider::new_default().await?;
let config = provider.get_configuration("grpc".to_string()).await?;
for (key, value) in config {
	println!("{} = {}", key, value);
}
# Ok(())
# }
Source

pub async fn update_configuration( &self, section: String, updates: HashMap<String, String>, ) -> Result<(), CommonError>

Updates configuration.

§Arguments
  • section - Configuration section
  • updates - Configuration updates as key-value pairs
§Returns
  • Ok(()) - Configuration updated successfully
  • Err(CommonError) - Update error

Trait Implementations§

Source§

impl Clone for AirServiceProvider

Source§

fn clone(&self) -> AirServiceProvider

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AirServiceProvider

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

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
§

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

§

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
§

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

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

§

impl<T> UserEvent for T
where T: Debug + Clone + Send + 'static,