Struct PartitionIdentifiers

Source
pub struct PartitionIdentifiers {
    pub id: Option<String>,
    pub label: Option<String>,
    pub part_label: Option<String>,
    pub part_uuid: Option<String>,
    pub path: Option<String>,
    pub uuid: Option<String>,
}
Expand description

A collection of all discoverable identifiers for a partition.

Fields§

§id: Option<String>§label: Option<String>§part_label: Option<String>§part_uuid: Option<String>§path: Option<String>§uuid: Option<String>

Implementations§

Source§

impl PartitionIdentifiers

Source

pub fn from_path<P: AsRef<Path>>(path: P) -> PartitionIdentifiers

Fetches all discoverable identifiers for a partition by the path to that partition.

Examples found in repository?
examples/example.rs (line 19)
7fn main() {
8    let mut args = env::args().skip(1);
9    match args.next() {
10        Some(arg) => match arg.as_str() {
11            "from-path" => {
12                let mut first = true;
13                for device in args {
14                    if !first {
15                        println!()
16                    }
17                    first = false;
18                    println!("{}:", device);
19                    println!("{:#?}", PartitionIdentifiers::from_path(device));
20                }
21            }
22            "by-id" => {
23                for id in args {
24                    let var = PartitionID::new_id(id.clone());
25                    println!("{}: {:?}", id, var.get_device_path());
26                }
27            }
28            "by-uuid" => {
29                for id in args {
30                    let var = PartitionID::new_uuid(id.clone());
31                    println!("{}: {:?}", id, var.get_device_path());
32                }
33            }
34            "by-partuuid" => {
35                for id in args {
36                    let var = PartitionID::new_partuuid(id.clone());
37                    println!("{}: {:?}", id, var.get_device_path());
38                }
39            }
40            "detect-by" => {
41                for id in args {
42                    let id = match PartitionID::from_disk_by_path(&id) {
43                        Ok(id) => id,
44                        Err(why) => {
45                            eprintln!("{}: {}", id, why);
46                            exit(1);
47                        }
48                    };
49
50                    println!("{:?} = {:?}", id, id.get_device_path());
51                }
52            }
53            _ => {
54                eprintln!(
55                    "invalid subcommand: valid commansd: [from-path, by-uuid, by-partuuid, ]"
56                );
57                exit(1);
58            }
59        },
60        None => {
61            eprintln!("must give subcommand: [from-path, by-uuid, by-partuuid, ]");
62            exit(1);
63        }
64    }
65}
Source

pub fn matches(&self, id: &PartitionID) -> bool

Checks if the given identity matches one of the available identifiers.

Trait Implementations§

Source§

impl Clone for PartitionIdentifiers

Source§

fn clone(&self) -> PartitionIdentifiers

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PartitionIdentifiers

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PartitionIdentifiers

Source§

fn default() -> PartitionIdentifiers

Returns the “default value” for a type. Read more
Source§

impl Hash for PartitionIdentifiers

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PartitionIdentifiers

Source§

fn eq(&self, other: &PartitionIdentifiers) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for PartitionIdentifiers

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.