partition_identity

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

                    println!("{:?} = {:?}", id, id.get_device_path());
                }
            }
            _ => {
                eprintln!(
                    "invalid subcommand: valid commansd: [from-path, by-uuid, by-partuuid, ]"
                );
                exit(1);
            }
        },
        None => {
            eprintln!("must give subcommand: [from-path, by-uuid, by-partuuid, ]");
            exit(1);
        }
    }
}
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 copy 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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.