partition_identity

Struct PartitionID

Source
pub struct PartitionID {
    pub variant: PartitionSource,
    pub id: String,
}
Expand description

Describes a partition identity.

A device path may be recovered from this.

§Notes

This is a struct instead of an enum to make access to the id string easier for situations where the variant does not need to be checked.

Fields§

§variant: PartitionSource§id: String

Implementations§

Source§

impl PartitionID

Source

pub fn new(variant: PartitionSource, id: String) -> Self

Construct a new PartitionID as the given source.

Source

pub fn new_id(id: String) -> Self

Construct a new PartitionID as a ID source.

Examples found in repository?
examples/example.rs (line 24)
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 new_label(id: String) -> Self

Construct a new PartitionID as a Label source.

Source

pub fn new_uuid(id: String) -> Self

Construct a new PartitionID as a UUID source.

Examples found in repository?
examples/example.rs (line 30)
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 new_partlabel(id: String) -> Self

Construct a new PartitionID as a PartLabel source.

Source

pub fn new_partuuid(id: String) -> Self

Construct a new PartitionID as a PartUUID source.

Examples found in repository?
examples/example.rs (line 36)
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 new_path(id: String) -> Self

Construct a new PartitionID as a Path source.

Source

pub fn get_device_path(&self) -> Option<PathBuf>

Find the device path of this ID.

Examples found in repository?
examples/example.rs (line 25)
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 get_source<P: AsRef<Path>>( variant: PartitionSource, path: P, ) -> Option<Self>

Find the given source ID of the device at the given path.

Source

pub fn get_uuid<P: AsRef<Path>>(path: P) -> Option<Self>

Find the UUID of the device at the given path.

Source

pub fn get_partuuid<P: AsRef<Path>>(path: P) -> Option<Self>

Find the PARTUUID of the device at the given path.

Source

pub fn from_disk_by_path<S: AsRef<str>>(path: S) -> Result<Self, Error>

Fetch a partition ID by a /dev/disk/by- path.

Examples found in repository?
examples/example.rs (line 42)
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);
        }
    }
}

Trait Implementations§

Source§

impl Clone for PartitionID

Source§

fn clone(&self) -> PartitionID

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 PartitionID

Source§

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

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

impl Display for PartitionID

Source§

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

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

impl FromStr for PartitionID

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(input: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for PartitionID

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 PartitionID

Source§

fn eq(&self, other: &PartitionID) -> 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 Eq for PartitionID

Source§

impl StructuralPartialEq for PartitionID

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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.