wslplugins_rs/core_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 `CoreDistributionInformation` 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
12use crate::{api::errors::require_update_error::Result, UserDistributionID};
13use std::ffi::OsString;
14
15/// A trait representing the core information of a WSL distribution.
16///
17/// This trait abstracts the common properties of a WSL distribution, such as its unique ID,
18/// display name, and package family name (if applicable).
19pub trait CoreDistributionInformation {
20 /// Retrieves the unique ID of the distribution.
21 ///
22 /// The ID is guaranteed to remain the same across reboots.
23 ///
24 /// # Returns
25 /// The [`UserDistributionID`] representing the distribution's unique identifier.
26 fn id(&self) -> UserDistributionID;
27
28 /// Retrieves the name of the distribution.
29 ///
30 /// # Returns
31 /// An [`OsString`] containing the display name of the distribution.
32 fn name(&self) -> OsString;
33
34 /// Retrieves the package family name of the distribution, if available.
35 ///
36 /// The package family name is applicable if the distribution is packaged.
37 ///
38 /// # Returns
39 /// - `Some(package_family_name)`: If the distribution has a package family name.
40 /// - `None`: If the distribution is not packaged or the information is unavailable.
41 fn package_family_name(&self) -> Option<OsString>;
42
43 /// Retrieves the type of distribution (ubuntu, debian, ...), if available.
44 ///
45 /// # Returns
46 /// - `Ok(Some(flavor)`: If the distribution has a flavor.
47 /// - `Ok(None)`: If the distribution does not have a falvour.
48 /// - `Err(e)`: if the API version is too low to retrieve this information.
49 /// # Errors
50 /// Returns an error if the API version is too low to retrieve this information.
51 fn flavor(&self) -> Result<Option<OsString>>;
52
53 /// Retrieves the version of the distribution, if available
54 ///
55 /// # Returns
56 /// - `Ok(Some(version)`: If the distribution version is available.
57 /// - `Ok(None)`: If the distribution does not have a specified version.
58 /// - `Err(e)`: if the API version is too low to retrieve this information.
59 /// # Errors
60 /// Returns an error if the API version is too low to retrieve this information.
61 fn version(&self) -> Result<Option<OsString>>;
62}