From f70e94a42731b8ba34c288730649fdf3866becd0 Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Thu, 21 Oct 2021 13:26:31 +0200 Subject: [PATCH] Added dedicated error for `std::path::Path` encoding. Fixed broken link in documentation. --- src/error.rs | 4 ++++ src/features/impl_std.rs | 2 +- src/lib.rs | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index e1aec77..a1e85fb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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 { diff --git a/src/features/impl_std.rs b/src/features/impl_std.rs index 2b6c59b..e59d465 100644 --- a/src/features/impl_std.rs +++ b/src/features/impl_std.rs @@ -184,7 +184,7 @@ impl Encode for &'_ Path { fn encode(&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), } } } diff --git a/src/lib.rs b/src/lib.rs index 8502006..5df6810 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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( val: E, dst: &mut [u8],