guppy/
package_id.rs
1use std::fmt;
5
6#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
8#[allow(clippy::derived_hash_with_manual_eq)] pub struct PackageId {
10 repr: Box<str>,
12}
13
14impl PackageId {
15 pub fn new(s: impl Into<Box<str>>) -> Self {
17 Self { repr: s.into() }
18 }
19
20 pub(super) fn from_metadata(id: cargo_metadata::PackageId) -> Self {
21 Self {
22 repr: id.repr.into_boxed_str(),
23 }
24 }
25
26 pub fn repr(&self) -> &str {
29 &self.repr
30 }
31}
32
33impl fmt::Display for PackageId {
34 fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
35 fmt::Display::fmt(&self.repr, f)
36 }
37}
38
39impl PartialEq<&PackageId> for PackageId {
40 fn eq(&self, other: &&PackageId) -> bool {
41 self.eq(*other)
42 }
43}
44
45impl PartialEq<PackageId> for &PackageId {
46 fn eq(&self, other: &PackageId) -> bool {
47 (*self).eq(other)
48 }
49}