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
impl AirServiceProvider
Sourcepub async fn new(address: String) -> Result<Self, CommonError>
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 providerErr(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(())
# }Sourcepub async fn new_default() -> Result<Self, CommonError>
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 providerErr(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(())
# }Sourcepub fn from_client(client: Arc<AirClient>) -> Self
pub fn from_client(client: Arc<AirClient>) -> Self
Sourcepub fn client(&self) -> &Arc<AirClient>
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
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Sourcepub async fn authenticate(
&self,
username: String,
password: String,
provider: String,
) -> Result<String, CommonError>
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 usernamepassword- User’s passwordprovider- Authentication provider (e.g., “github”, “gitlab”, “microsoft”)
§Returns
Ok(token)- Authentication token if successfulErr(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(())
# }Sourcepub async fn check_for_updates(
&self,
current_version: String,
channel: String,
) -> Result<Option<UpdateInfo>, CommonError>
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 versionchannel- Update channel (e.g., “stable”, “beta”, “nightly”)
§Returns
Ok(Some(update))- Update available with informationOk(None)- No update availableErr(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(())
# }Sourcepub async fn download_update(
&self,
url: String,
destination_path: String,
checksum: String,
) -> Result<FileInfo, CommonError>
pub async fn download_update( &self, url: String, destination_path: String, checksum: String, ) -> Result<FileInfo, CommonError>
Sourcepub async fn apply_update(
&self,
version: String,
update_path: String,
) -> Result<(), CommonError>
pub async fn apply_update( &self, version: String, update_path: String, ) -> Result<(), CommonError>
Sourcepub async fn download_file(
&self,
url: String,
destination_path: String,
checksum: String,
) -> Result<FileInfo, CommonError>
pub async fn download_file( &self, url: String, destination_path: String, checksum: String, ) -> Result<FileInfo, CommonError>
Sourcepub async fn download_stream(
&self,
url: String,
headers: HashMap<String, String>,
) -> Result<DownloadStream, CommonError>
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 downloadheaders- Optional HTTP headers
§Returns
Ok(stream)- Stream that yields download chunksErr(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(())
# }Sourcepub async fn index_files(
&self,
path: String,
patterns: Vec<String>,
exclude_patterns: Vec<String>,
max_depth: u32,
) -> Result<IndexInfo, CommonError>
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 indexpatterns- 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 sizeErr(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(())
# }Sourcepub async fn search_files(
&self,
query: String,
path: String,
max_results: u32,
) -> Result<Vec<FileResult>, CommonError>
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 stringpath- 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 resultsErr(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(())
# }Sourcepub async fn get_file_info(
&self,
path: String,
) -> Result<ExtendedFileInfo, CommonError>
pub async fn get_file_info( &self, path: String, ) -> Result<ExtendedFileInfo, CommonError>
Sourcepub async fn get_status(&self) -> Result<AirStatus, CommonError>
pub async fn get_status(&self) -> Result<AirStatus, CommonError>
Gets the status of the Air daemon.
§Returns
Ok(status)- Air daemon status informationErr(CommonError)- Request error
Sourcepub async fn health_check(&self) -> Result<bool, CommonError>
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(())
# }Sourcepub async fn get_metrics(
&self,
metric_type: Option<String>,
) -> Result<AirMetrics, CommonError>
pub async fn get_metrics( &self, metric_type: Option<String>, ) -> Result<AirMetrics, CommonError>
Sourcepub async fn get_resource_usage(&self) -> Result<ResourceUsage, CommonError>
pub async fn get_resource_usage(&self) -> Result<ResourceUsage, CommonError>
Gets resource usage information.
§Returns
Ok(usage)- Resource usage dataErr(CommonError)- Request error
Sourcepub async fn set_resource_limits(
&self,
memory_limit_mb: u32,
cpu_limit_percent: u32,
disk_limit_mb: u32,
) -> Result<(), CommonError>
pub async fn set_resource_limits( &self, memory_limit_mb: u32, cpu_limit_percent: u32, disk_limit_mb: u32, ) -> Result<(), CommonError>
Sourcepub async fn get_configuration(
&self,
section: String,
) -> Result<HashMap<String, String>, CommonError>
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 pairsErr(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(())
# }Sourcepub async fn update_configuration(
&self,
section: String,
updates: HashMap<String, String>,
) -> Result<(), CommonError>
pub async fn update_configuration( &self, section: String, updates: HashMap<String, String>, ) -> Result<(), CommonError>
Trait Implementations§
Source§impl Clone for AirServiceProvider
impl Clone for AirServiceProvider
Source§fn clone(&self) -> AirServiceProvider
fn clone(&self) -> AirServiceProvider
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AirServiceProvider
impl !RefUnwindSafe for AirServiceProvider
impl Send for AirServiceProvider
impl Sync for AirServiceProvider
impl Unpin for AirServiceProvider
impl !UnwindSafe for AirServiceProvider
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].