Skip to content

Commit cfa9421

Browse files
committed
docs(schema): Document newtypes
1 parent acef3c0 commit cfa9421

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/cargo/util_schemas/manifest.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ impl TomlTarget {
11121112

11131113
macro_rules! str_newtype {
11141114
($name:ident) => {
1115+
/// Verified string newtype
11151116
#[derive(Serialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
11161117
#[serde(transparent)]
11171118
pub struct $name<T: AsRef<str> = String>(T);
@@ -1171,13 +1172,17 @@ macro_rules! str_newtype {
11711172
str_newtype!(PackageName);
11721173

11731174
impl<T: AsRef<str>> PackageName<T> {
1175+
/// Validated package name
11741176
pub fn new(name: T) -> Result<Self> {
11751177
restricted_names::validate_package_name(name.as_ref(), "package name", "")?;
11761178
Ok(Self(name))
11771179
}
11781180
}
11791181

11801182
impl PackageName {
1183+
/// Coerce a value to be a validate package name
1184+
///
1185+
/// Replaces invalid values with `placeholder`
11811186
pub fn sanitize(name: impl AsRef<str>, placeholder: char) -> Self {
11821187
PackageName(restricted_names::sanitize_package_name(
11831188
name.as_ref(),
@@ -1189,6 +1194,7 @@ impl PackageName {
11891194
str_newtype!(RegistryName);
11901195

11911196
impl<T: AsRef<str>> RegistryName<T> {
1197+
/// Validated registry name
11921198
pub fn new(name: T) -> Result<Self> {
11931199
restricted_names::validate_package_name(name.as_ref(), "registry name", "")?;
11941200
Ok(Self(name))
@@ -1198,6 +1204,7 @@ impl<T: AsRef<str>> RegistryName<T> {
11981204
str_newtype!(ProfileName);
11991205

12001206
impl<T: AsRef<str>> ProfileName<T> {
1207+
/// Validated profile name
12011208
pub fn new(name: T) -> Result<Self> {
12021209
restricted_names::validate_profile_name(name.as_ref())?;
12031210
Ok(Self(name))
@@ -1207,6 +1214,7 @@ impl<T: AsRef<str>> ProfileName<T> {
12071214
str_newtype!(FeatureName);
12081215

12091216
impl<T: AsRef<str>> FeatureName<T> {
1217+
/// Validated feature name
12101218
pub fn new(name: T) -> Result<Self> {
12111219
restricted_names::validate_feature_name(name.as_ref())?;
12121220
Ok(Self(name))

0 commit comments

Comments
 (0)