From fb4f0be1f3f2563e0f89bd8b507dc57cc162ff74 Mon Sep 17 00:00:00 2001 From: DerZade Date: Tue, 5 Sep 2023 20:55:48 +0200 Subject: [PATCH 1/2] feat: implement std::error::Error for InvalidBits implement std::error::Error for InvalidBits and hide it behind a "std"-feature-flag to ensure non_std compatibility out of the box --- Cargo.toml | 3 +++ src/lib.rs | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 20daf2a..2aef39f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,9 @@ homepage = "https://github.com/enarx/flagset" documentation = "https://docs.rs/flagset" description = "Data types and a macro for generating enumeration-based bit flags" +[features] +std = [] + [dependencies.serde] version = "1.0" optional = true diff --git a/src/lib.rs b/src/lib.rs index c44b04b..8eb14fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -245,7 +245,7 @@ appropriate `repr` attribute: )] #![allow(unknown_lints)] #![warn(clippy::all)] -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] use core::fmt::{Debug, Formatter, Result}; use core::ops::*; @@ -276,6 +276,9 @@ impl core::fmt::Display for InvalidBits { } } +#[cfg(feature = "std")] +impl std::error::Error for InvalidBits {} + #[doc(hidden)] pub trait Flags: Copy From 419c3d198b87a32ef6d8f5f8c9ed48a871c2170a Mon Sep 17 00:00:00 2001 From: DerZade Date: Tue, 5 Sep 2023 20:56:32 +0200 Subject: [PATCH 2/2] chore: use doc_auto_cfg feature for docs.rs builds --- Cargo.toml | 1 + src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 2aef39f..d644ebc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,3 +29,4 @@ version = "0.1" [package.metadata.docs.rs] all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/src/lib.rs b/src/lib.rs index 8eb14fc..273f238 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -246,6 +246,7 @@ appropriate `repr` attribute: #![allow(unknown_lints)] #![warn(clippy::all)] #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] use core::fmt::{Debug, Formatter, Result}; use core::ops::*;