Added dedicated error for `std::path::Path` encoding. Fixed broken link in documentation.

This commit is contained in:
Victor Koenders 2021-10-21 13:26:31 +02:00
parent 6ff33cd8c2
commit f70e94a427
3 changed files with 7 additions and 3 deletions

View File

@ -18,6 +18,10 @@ pub enum EncodeError {
/// An uncommon error occured, see the inner text for more information
Other(&'static str),
/// A `std::path::Path` was being encoded but did not contain a valid `&str` representation
#[cfg(feature = "std")]
InvalidPathCharacters,
/// The targetted writer encountered an `std::io::Error`
#[cfg(feature = "std")]
Io {

View File

@ -184,7 +184,7 @@ impl Encode for &'_ Path {
fn encode<E: Encoder>(&self, encoder: E) -> Result<(), EncodeError> {
match self.to_str() {
Some(str) => str.encode(encoder),
None => Err(EncodeError::Other("Path contains invalid UTF-8 characters")),
None => Err(EncodeError::InvalidPathCharacters),
}
}
}

View File

@ -45,9 +45,9 @@ use config::Config;
/// Encode the given value into the given slice. Returns the amount of bytes that have been written.
///
/// Will take the [Default] configuration. See the [config] module for more information.
/// Will take the [standard] configuration. See the [config] module for more information.
///
/// [Default]: config/struct.Default.html
/// [standard]: config/struct.Configuration.html#method.standard
pub fn encode_into_slice<E: enc::Encode>(
val: E,
dst: &mut [u8],