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
impl PartitionID
Sourcepub fn new(variant: PartitionSource, id: String) -> Self
pub fn new(variant: PartitionSource, id: String) -> Self
Construct a new PartitionID
as the given source.
Sourcepub fn new_id(id: String) -> Self
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);
}
}
}
Sourcepub fn new_uuid(id: String) -> Self
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);
}
}
}
Sourcepub fn new_partlabel(id: String) -> Self
pub fn new_partlabel(id: String) -> Self
Construct a new PartitionID
as a PartLabel
source.
Sourcepub fn new_partuuid(id: String) -> Self
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);
}
}
}
Sourcepub fn get_device_path(&self) -> Option<PathBuf>
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);
}
}
}
Sourcepub fn get_source<P: AsRef<Path>>(
variant: PartitionSource,
path: P,
) -> Option<Self>
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.
Sourcepub fn get_uuid<P: AsRef<Path>>(path: P) -> Option<Self>
pub fn get_uuid<P: AsRef<Path>>(path: P) -> Option<Self>
Find the UUID of the device at the given path.
Sourcepub fn get_partuuid<P: AsRef<Path>>(path: P) -> Option<Self>
pub fn get_partuuid<P: AsRef<Path>>(path: P) -> Option<Self>
Find the PARTUUID of the device at the given path.
Sourcepub fn from_disk_by_path<S: AsRef<str>>(path: S) -> Result<Self, Error>
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
impl Clone for PartitionID
Source§fn clone(&self) -> PartitionID
fn clone(&self) -> PartitionID
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for PartitionID
impl Debug for PartitionID
Source§impl Display for PartitionID
impl Display for PartitionID
Source§impl FromStr for PartitionID
impl FromStr for PartitionID
Source§impl Hash for PartitionID
impl Hash for PartitionID
Source§impl PartialEq for PartitionID
impl PartialEq for PartitionID
impl Eq for PartitionID
impl StructuralPartialEq for PartitionID
Auto Trait Implementations§
impl Freeze for PartitionID
impl RefUnwindSafe for PartitionID
impl Send for PartitionID
impl Sync for PartitionID
impl Unpin for PartitionID
impl UnwindSafe for PartitionID
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more