Skip to content

Commit

Permalink
Adds no_std supports
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Sep 6, 2024
1 parent 3926e0c commit 0061c4c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::error::Error;
use std::fmt::Formatter;
#![no_std]

use core::error::Error;
use core::fmt::Formatter;

/// Provides a method to get a [`Display`].
///
Expand All @@ -24,17 +26,17 @@ impl ErrorDisplay for dyn Error {
/// Implementation of [`std::fmt::Display`] for display an error and its nested errors.
pub struct Display<'a>(&'a dyn Error);

impl<'a> std::fmt::Display for Display<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
impl<'a> core::fmt::Display for Display<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
// Write top-level error.
std::fmt::Display::fmt(self.0, f)?;
core::fmt::Display::fmt(self.0, f)?;

// Write nested errors.
let mut next = self.0.source();

while let Some(e) = next {
f.write_str(" -> ")?;
std::fmt::Display::fmt(e, f)?;
core::fmt::Display::fmt(e, f)?;
next = e.source();
}

Expand All @@ -45,8 +47,11 @@ impl<'a> std::fmt::Display for Display<'a> {
#[cfg(test)]
mod tests {
use super::*;
use std::prelude::rust_2021::*;
use thiserror::Error;

extern crate std;

#[test]
fn single() {
let e = TestError::Single;
Expand Down

0 comments on commit 0061c4c

Please sign in to comment.