Skip to content

Commit ce3943f

Browse files
Merge remote-tracking branch 'repoconf-rust-public-lib-template/main'
2 parents 0d39d20 + 29fc0f7 commit ce3943f

File tree

8 files changed

+1897
-164
lines changed

8 files changed

+1897
-164
lines changed
Lines changed: 94 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929
* Good: `#[error("user '{name}' not found")]`
3030
* Bad: `#[error("user {name} not found")]`
3131

32-
# Files
32+
## Files
3333

3434
## File: src/drafts.rs
35+
3536
````rust
3637
pub mod err_vec_display;
3738
````
3839

3940
## File: src/functions/exit_result.rs
41+
4042
````rust
4143
use crate::eprintln_error;
4244
use std::error::Error;
@@ -55,6 +57,7 @@ pub fn exit_result<E: Error + 'static>(result: Result<(), E>) -> ExitCode {
5557
````
5658

5759
## File: src/functions/partition_result.rs
60+
5861
````rust
5962
use alloc::vec::Vec;
6063

@@ -88,6 +91,7 @@ pub fn partition_result<T, E>(results: impl IntoIterator<Item = Result<T, E>>) -
8891
````
8992

9093
## File: src/functions/write_to_named_temp_file.rs
94+
9195
````rust
9296
use crate::{handle, map_err};
9397
use std::fs::File;
@@ -123,6 +127,7 @@ pub enum WriteErrorDebugToTempFileError {
123127
````
124128

125129
## File: src/types/err_vec.rs
130+
126131
````rust
127132
use std::error::Error;
128133
use std::fmt::{Display, Formatter};
@@ -177,6 +182,7 @@ impl<E: Error + 'static> From<Vec<E>> for ErrVec {
177182
````
178183

179184
## File: src/types/item_error.rs
185+
180186
````rust
181187
use thiserror::Error;
182188

@@ -192,6 +198,7 @@ pub struct ItemError<T, E> {
192198
````
193199

194200
## File: src/types/path_buf_display.rs
201+
195202
````rust
196203
use crate::DisplayAsDebug;
197204
use std::path::PathBuf;
@@ -201,6 +208,7 @@ pub type PathBufDisplay = DisplayAsDebug<PathBuf>;
201208
````
202209

203210
## File: src/types/prefixer.rs
211+
204212
````rust
205213
use std::fmt;
206214
use std::io::{self, Write};
@@ -285,6 +293,7 @@ impl<'w> Write for Prefixer<'w> {
285293
````
286294

287295
## File: src/functions/get_root_error.rs
296+
288297
````rust
289298
use core::error::Error;
290299

@@ -298,82 +307,8 @@ pub fn get_root_source(error: &dyn Error) -> &dyn Error {
298307
}
299308
````
300309

301-
## File: src/types/debug_as_display.rs
302-
````rust
303-
use core::fmt::{Debug, Display, Formatter};
304-
305-
/// A wrapper that renders `Debug` using the inner type's `Display` implementation.
306-
/// This wrapper is needed for types that have an easy-to-understand `Display` impl but hard-to-understand `Debug` impl.
307-
#[derive(Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
308-
pub struct DebugAsDisplay<T: Display>(
309-
/// Inner value rendered with `Display` for both `Debug` and `Display`.
310-
pub T,
311-
);
312-
313-
impl<T: Display> Debug for DebugAsDisplay<T> {
314-
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
315-
Display::fmt(&self.0, f)
316-
}
317-
}
318-
319-
impl<T: Display> Display for DebugAsDisplay<T> {
320-
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
321-
Display::fmt(&self.0, f)
322-
}
323-
}
324-
325-
impl<T: Display> From<T> for DebugAsDisplay<T> {
326-
fn from(value: T) -> Self {
327-
Self(value)
328-
}
329-
}
330-
````
331-
332-
## File: src/types/display_as_debug.rs
333-
````rust
334-
use core::fmt::{Debug, Display, Formatter};
335-
336-
/// A wrapper that renders `Display` using the inner type's `Debug` implementation.
337-
#[derive(Ord, PartialOrd, Eq, PartialEq, Copy, Clone, Debug)]
338-
pub struct DisplayAsDebug<T: Debug>(
339-
/// Inner value rendered with `Debug` for `Display`.
340-
pub T,
341-
);
342-
343-
impl<T: Debug> Display for DisplayAsDebug<T> {
344-
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
345-
Debug::fmt(&self.0, f)
346-
}
347-
}
348-
349-
impl<T: Debug> From<T> for DisplayAsDebug<T> {
350-
fn from(value: T) -> Self {
351-
Self(value)
352-
}
353-
}
354-
````
355-
356-
## File: src/functions.rs
357-
````rust
358-
mod get_root_error;
359-
mod partition_result;
360-
361-
pub use get_root_error::*;
362-
pub use partition_result::*;
363-
364-
cfg_if::cfg_if! {
365-
if #[cfg(feature = "std")] {
366-
mod writeln_error;
367-
mod write_to_named_temp_file;
368-
mod exit_result;
369-
pub use writeln_error::*;
370-
pub use write_to_named_temp_file::*;
371-
pub use exit_result::*;
372-
}
373-
}
374-
````
375-
376310
## File: src/functions/writeln_error.rs
311+
377312
````rust
378313
use crate::{ErrVec, Prefixer, write_to_named_temp_file};
379314
use std::error::Error;
@@ -526,7 +461,86 @@ mod tests {
526461
}
527462
````
528463

464+
## File: src/types/debug_as_display.rs
465+
466+
````rust
467+
use core::fmt::{Debug, Display, Formatter};
468+
469+
/// A wrapper that renders `Debug` using the inner type's `Display` implementation.
470+
/// This wrapper is needed for types that have an easy-to-understand `Display` impl but hard-to-understand `Debug` impl.
471+
#[derive(Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
472+
pub struct DebugAsDisplay<T: Display>(
473+
/// Inner value rendered with `Display` for both `Debug` and `Display`.
474+
pub T,
475+
);
476+
477+
impl<T: Display> Debug for DebugAsDisplay<T> {
478+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
479+
Display::fmt(&self.0, f)
480+
}
481+
}
482+
483+
impl<T: Display> Display for DebugAsDisplay<T> {
484+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
485+
Display::fmt(&self.0, f)
486+
}
487+
}
488+
489+
impl<T: Display> From<T> for DebugAsDisplay<T> {
490+
fn from(value: T) -> Self {
491+
Self(value)
492+
}
493+
}
494+
````
495+
496+
## File: src/types/display_as_debug.rs
497+
498+
````rust
499+
use core::fmt::{Debug, Display, Formatter};
500+
501+
/// A wrapper that renders `Display` using the inner type's `Debug` implementation.
502+
#[derive(Ord, PartialOrd, Eq, PartialEq, Copy, Clone, Debug)]
503+
pub struct DisplayAsDebug<T: Debug>(
504+
/// Inner value rendered with `Debug` for `Display`.
505+
pub T,
506+
);
507+
508+
impl<T: Debug> Display for DisplayAsDebug<T> {
509+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
510+
Debug::fmt(&self.0, f)
511+
}
512+
}
513+
514+
impl<T: Debug> From<T> for DisplayAsDebug<T> {
515+
fn from(value: T) -> Self {
516+
Self(value)
517+
}
518+
}
519+
````
520+
521+
## File: src/functions.rs
522+
523+
````rust
524+
mod get_root_error;
525+
mod partition_result;
526+
527+
pub use get_root_error::*;
528+
pub use partition_result::*;
529+
530+
cfg_if::cfg_if! {
531+
if #[cfg(feature = "std")] {
532+
mod writeln_error;
533+
mod write_to_named_temp_file;
534+
mod exit_result;
535+
pub use writeln_error::*;
536+
pub use write_to_named_temp_file::*;
537+
pub use exit_result::*;
538+
}
539+
}
540+
````
541+
529542
## File: src/types.rs
543+
530544
````rust
531545
mod debug_as_display;
532546
mod display_as_debug;
@@ -550,6 +564,7 @@ cfg_if::cfg_if! {
550564
````
551565

552566
## File: src/macros.rs
567+
553568
````rust
554569
/// [`handle!`](crate::handle) is a better alternative to [`map_err`](Result::map_err) because it doesn't capture any variables from the environment if the result is [`Ok`], only when the result is [`Err`].
555570
/// By contrast, a closure passed to `map_err` always captures the variables from environment, regardless of whether the result is [`Ok`] or [`Err`]
@@ -1021,6 +1036,7 @@ mod tests {
10211036
````
10221037

10231038
## File: src/lib.rs
1039+
10241040
````rust
10251041
//! Macros for ergonomic error handling with [thiserror](https://crates.io/crates/thiserror).
10261042
//!
@@ -1057,9 +1073,9 @@ mod tests {
10571073
//!
10581074
//! #[derive(Error, Debug)]
10591075
//! enum ParseConfigError {
1060-
//! #[error("failed to read file to string: '{}'", path.display())]
1076+
//! #[error("failed to read file to string: '{path}'")]
10611077
//! ReadToStringFailed { path: PathBuf, source: std::io::Error },
1062-
//! #[error("failed to parse the file contents into config: '{}'", path.display())]
1078+
//! #[error("failed to parse the file contents into config: '{path}'")]
10631079
//! DeserializeFailed { path: PathBuf, contents: String, source: serde_json::Error }
10641080
//! }
10651081
//! # }

0 commit comments

Comments
 (0)