Skip to main content

wslplugins_rs/
core_wsl_distribution_information.rs

1//! # Core Distribution Information
2//!
3//! This module defines a trait to represent core information about a WSL distribution.
4//! It provides methods to retrieve essential details such as the distribution ID, name,
5//! and package family name, offering a consistent interface for interacting with WSL distributions.
6//!
7//! ## Overview
8//! The `CoreWSLDistributionInformation` trait is designed to abstract the key properties
9//! of a distribution. Implementing this trait allows for seamless integration with systems
10//! that need to handle multiple distributions in a consistent manner.
11
12#[cfg(doc)]
13use crate::WSLVersionCapability;
14use crate::{api::errors::require_update_error::Result, UserDistributionID};
15use std::ffi::OsString;
16
17/// A trait representing the core information of a WSL distribution.
18///
19/// This trait abstracts the common properties of a WSL distribution, such as its unique ID,
20/// display name, and package family name (if applicable).
21pub trait CoreWSLDistributionInformation {
22    /// Retrieves the unique ID of the distribution.
23    ///
24    /// The ID is guaranteed to remain the same across reboots.
25    ///
26    /// # Returns
27    /// The [`UserDistributionID`] representing the distribution's unique identifier.
28    fn id(&self) -> UserDistributionID;
29
30    /// Retrieves the name of the distribution.
31    ///
32    /// # Returns
33    /// An [`OsString`] containing the display name of the distribution.
34    fn name(&self) -> OsString;
35
36    /// Retrieves the package family name of the distribution, if available.
37    ///
38    /// The package family name is applicable if the distribution is packaged.
39    ///
40    /// # Returns
41    /// - `Some(package_family_name)`: If the distribution has a package family name.
42    /// - `None`: If the distribution is not packaged or the information is unavailable.
43    fn package_family_name(&self) -> Option<OsString>;
44
45    /// Retrieves the type of distribution (ubuntu, debian, ...), if available.
46    ///
47    /// This requires [`WSLVersionCapability::DistributionFlavor`] (`2.4.4`).
48    ///
49    /// # Returns
50    /// - `Ok(Some(flavor)`: If the distribution has a flavor.
51    /// - `Ok(None)`: If the distribution does not have a falvour.
52    /// - `Err(e)`: if the API version is too low to retrieve this information.
53    /// # Errors
54    /// Returns an error if the API version is too low to retrieve this information.
55    fn flavor(&self) -> Result<Option<OsString>>;
56
57    /// Retrieves the version of the distribution, if available
58    ///
59    /// This requires [`WSLVersionCapability::DistributionVersion`] (`2.4.4`).
60    ///
61    /// # Returns
62    /// - `Ok(Some(version)`: If the distribution version is available.
63    /// - `Ok(None)`: If the distribution does not have a specified version.
64    /// - `Err(e)`: if the API version is too low to retrieve this information.
65    /// # Errors
66    /// Returns an error if the API version is too low to retrieve this information.
67    fn version(&self) -> Result<Option<OsString>>;
68}