cargo_lock/package/
name.rs1use crate::Error;
4use serde::{Deserialize, Serialize};
5use std::{fmt, str::FromStr};
6
7#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize)]
9pub struct Name(String);
10
11impl Name {
12 pub fn as_str(&self) -> &str {
14 &self.0
15 }
16}
17
18impl AsRef<str> for Name {
19 fn as_ref(&self) -> &str {
20 self.as_str()
21 }
22}
23
24impl fmt::Display for Name {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 self.0.fmt(f)
27 }
28}
29
30impl From<Name> for String {
31 fn from(name: Name) -> String {
32 name.0
33 }
34}
35
36impl FromStr for Name {
37 type Err = Error;
38
39 fn from_str(s: &str) -> Result<Self, Error> {
40 Ok(Name(s.into()))
42 }
43}