rust_toolchain/
component.rs

1use std::borrow::Cow;
2
3/// A toolchain component
4///
5/// # Reading materials
6///
7/// - [`rustup component history`]
8///
9/// [`rustup concepts: components`]: https://rust-lang.github.io/rustup/concepts/components.html
10/// [`rustup component history`]: https://rust-lang.github.io/rustup-components-history/
11#[derive(Clone, Debug, Hash, Eq, PartialEq)]
12pub struct Component {
13    name: Cow<'static, str>,
14}
15
16impl Component {
17    /// Create a new Component instance
18    pub fn new(name: impl Into<Cow<'static, str>>) -> Self {
19        Self { name: name.into() }
20    }
21
22    /// The name of the component
23    pub fn name(&self) -> &str {
24        self.name.as_ref()
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn new_instance() {
34        let c = Component::new("sample");
35        assert_eq!(c.name(), "sample");
36    }
37}