wslplugins-rs 0.1.0-beta.2

A Rust framework for developing WSL plugins using safe and idiomatic Rust.
Documentation
//! # Core Distribution Information
//!
//! This module defines a trait to represent core information about a WSL distribution.
//! It provides methods to retrieve essential details such as the distribution ID, name,
//! and package family name, offering a consistent interface for interacting with WSL distributions.
//!
//! ## Overview
//! The `CoreDistributionInformation` trait is designed to abstract the key properties
//! of a distribution. Implementing this trait allows for seamless integration with systems
//! that need to handle multiple distributions in a consistent manner.

use crate::{api::errors::require_update_error::Result, UserDistributionID};
use std::ffi::OsString;

/// A trait representing the core information of a WSL distribution.
///
/// This trait abstracts the common properties of a WSL distribution, such as its unique ID,
/// display name, and package family name (if applicable).
pub trait CoreDistributionInformation {
    /// Retrieves the unique ID of the distribution.
    ///
    /// The ID is guaranteed to remain the same across reboots.
    ///
    /// # Returns
    /// The [`UserDistributionID`] representing the distribution's unique identifier.
    fn id(&self) -> UserDistributionID;

    /// Retrieves the name of the distribution.
    ///
    /// # Returns
    /// An [`OsString`] containing the display name of the distribution.
    fn name(&self) -> OsString;

    /// Retrieves the package family name of the distribution, if available.
    ///
    /// The package family name is applicable if the distribution is packaged.
    ///
    /// # Returns
    /// - `Some(package_family_name)`: If the distribution has a package family name.
    /// - `None`: If the distribution is not packaged or the information is unavailable.
    fn package_family_name(&self) -> Option<OsString>;

    /// Retrieves the type of distribution (ubuntu, debian, ...), if available.
    ///
    /// # Returns
    /// - `Ok(Some(flavor)`: If the distribution has a flavor.
    /// - `Ok(None)`: If the distribution does not have a falvour.
    /// - `Err(e)`: if the API version is too low to retrieve this information.
    /// # Errors
    /// Returns an error if the API version is too low to retrieve this information.
    fn flavor(&self) -> Result<Option<OsString>>;

    /// Retrieves the version of the distribution, if available
    ///
    /// # Returns
    /// - `Ok(Some(version)`: If the distribution version is available.
    /// - `Ok(None)`: If the distribution does not have a specified version.
    /// - `Err(e)`: if the API version is too low to retrieve this information.
    /// # Errors
    /// Returns an error if the API version is too low to retrieve this information.
    fn version(&self) -> Result<Option<OsString>>;
}