Skip to content

Commit a1fda4d

Browse files
committed
Add Error::unknown_field_path_with_alts
1 parent 6158749 commit a1fda4d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

core/src/error/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ impl Error {
125125
Error::new(ErrorUnknownField::with_alts(field, alternates).into())
126126
}
127127

128+
/// Creates a new error for a field name that appears in the input but does not correspond to
129+
/// a known attribute. The second argument is the list of known attributes; if a similar name
130+
/// is found that will be shown in the emitted error message.
131+
pub fn unknown_field_path_with_alts<'a, T, I>(field: &Path, alternates: I) -> Self
132+
where
133+
T: AsRef<str> + 'a,
134+
I: IntoIterator<Item = &'a T>,
135+
{
136+
Error::new(ErrorUnknownField::with_alts(&path_to_string(field), alternates).into())
137+
}
138+
128139
/// Creates a new error for a struct or variant that does not adhere to the supported shape.
129140
pub fn unsupported_shape(shape: &str) -> Self {
130141
Error::new(ErrorKind::UnsupportedShape {

0 commit comments

Comments
 (0)