-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rodrimati1992/0_1_patch
0.1.1 patch
- Loading branch information
Showing
18 changed files
with
930 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "const_panic" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
authors = ["rodrimati1992 <[email protected]>"] | ||
edition = "2021" | ||
license = "Zlib" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
This changelog is a summary of the changes made in each release. | ||
|
||
# 0.1 | ||
|
||
### 0.1.1 | ||
|
||
Added `PanicFmt`-based formatting for these types(all of which require the `"non_basic"` feature): | ||
- `Option`s of integer, bool, and `&str` | ||
- `Option`s of arrays and slices (of integer, bool, and `&str`) | ||
- `NonZero*` integers, and `Option`s of them | ||
- `NonNull`, and `Option`s of them | ||
- `*const T` and `*mut T` | ||
- `std::cmp::Ordering`, and `Option`s of them | ||
- `std::sync::atomic::Ordering` | ||
- `std::ops::Range*` types, parameterized with `usize`. | ||
- `()` | ||
- `std::marker::PhantomData` | ||
- `std::marker::PhantomPinned` | ||
- `StdWrapper` | ||
|
||
Added these macros: | ||
- `unwrap_ok` | ||
- `unwrap_err` | ||
- `unwrap_some` | ||
|
||
Fixed signature of to_panicvals for arrays and slices of PanicVals, by adding a `FmtArg` parameter. | ||
|
||
|
||
### 0.1.0 | ||
|
||
Defined the `fmt::PanicFmt` trait. | ||
|
||
Defined these types in the `fmt` module: | ||
- `ComputePvCount` | ||
- `FmtArg` | ||
- `IsCustomType` | ||
- `IsStdType` | ||
- `IsPanicFMt` | ||
- `Separator` | ||
- `Delimiter` | ||
- `FmtKind` | ||
- `IsLast` | ||
- `TypeDelim` | ||
- `ShortString` (type alias for `ArrayString<16>`) | ||
|
||
Defined these constants in the `fmt` module: | ||
- `COMMA_SEP` | ||
- `COMMA_TERM` | ||
- `INDENTATION_STEP` | ||
|
||
Re-exported these variants from `fmt::Delimiter` in `fmt`: | ||
- `CloseBrace` | ||
- `CloseBracket` | ||
- `CloseParen` | ||
- `Empty` renamed to `EmptyDelimiter` | ||
- `OpenBrace` | ||
- `OpenBracket` | ||
- `OpenParen` | ||
|
||
Reexported these items from `fmt` in the root module: | ||
- `FmtArg` | ||
- `IsCustomType` | ||
- `PanicFmt` | ||
- `ComputePvCount` | ||
- `TypeDelim` | ||
|
||
|
||
Defined these macros: | ||
- `coerce_fmt` | ||
- `concat_panic`: for panicking with formatted arguments. | ||
- `flatten_panicvals`: for flattening the argument slices of `PanicVal`s into an array. | ||
- `impl_panicfmt`: for user-defined structs and enums to implement `PanicFmt` | ||
- `inline_macro` | ||
|
||
Implemented `PanicFmt`-based formatting for: | ||
- All the primitive integer types | ||
- `str` | ||
- `bool` | ||
- Arrays and slices of `PanicVal` integers, `bool`, and `&str`. | ||
|
||
Defined the `ArrayString` stack allocated string type. | ||
|
||
Defined the `PanicVal` opaque enum used for formatting. | ||
|
||
Defined the `StdWrapper` wrapper type for defining methods on `std` types | ||
|
||
Defined the `concat_panic` function, for panicking with formatted arguments. | ||
|
||
Defined the `"non_basic"` crate feature, | ||
which enables all items for doing more than panicking with primitive types. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use crate::{FmtArg, PanicFmt, PanicVal, StdWrapper}; | ||
|
||
use core::ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive}; | ||
|
||
macro_rules! impl_range_panicfmt_one { | ||
( | ||
fn(&$self:ident: $ty:ty, $f:ident) -> $pv_count:literal { | ||
$($content:tt)* | ||
} | ||
) => { | ||
impl PanicFmt for $ty { | ||
type This = Self; | ||
type Kind = crate::fmt::IsStdType; | ||
const PV_COUNT: usize = $pv_count; | ||
} | ||
|
||
impl crate::StdWrapper<&$ty> { | ||
#[doc = concat!( | ||
"Converts this `", stringify!($ty), "` to a single-element `PanicVal` array." | ||
)] | ||
pub const fn to_panicvals($self, $f: FmtArg) -> [PanicVal<'static>; $pv_count] { | ||
$($content)* | ||
} | ||
} | ||
} | ||
} | ||
|
||
macro_rules! impl_range_panicfmt { | ||
($elem_ty:ty) => { | ||
impl_range_panicfmt_one! { | ||
fn(&self: Range<$elem_ty>, f) -> 3 { | ||
[ | ||
StdWrapper(&self.0.start).to_panicval(f), | ||
PanicVal::write_str(".."), | ||
StdWrapper(&self.0.end).to_panicval(f), | ||
] | ||
} | ||
} | ||
|
||
impl_range_panicfmt_one! { | ||
fn(&self: RangeFrom<$elem_ty>, f) -> 2 { | ||
[ | ||
StdWrapper(&self.0.start).to_panicval(f), | ||
PanicVal::write_str(".."), | ||
] | ||
} | ||
} | ||
|
||
impl_range_panicfmt_one! { | ||
fn(&self: RangeTo<$elem_ty>, f) -> 2 { | ||
[ | ||
PanicVal::write_str(".."), | ||
StdWrapper(&self.0.end).to_panicval(f), | ||
] | ||
} | ||
} | ||
|
||
impl_range_panicfmt_one! { | ||
fn(&self: RangeToInclusive<$elem_ty>, f) -> 2 { | ||
[ | ||
PanicVal::write_str("..="), | ||
StdWrapper(&self.0.end).to_panicval(f), | ||
] | ||
} | ||
} | ||
|
||
impl_range_panicfmt_one! { | ||
fn(&self: RangeInclusive<$elem_ty>, f) -> 3 { | ||
[ | ||
StdWrapper(self.0.start()).to_panicval(f), | ||
PanicVal::write_str("..="), | ||
StdWrapper(self.0.end()).to_panicval(f), | ||
] | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_range_panicfmt! {usize} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
impl_range_panicfmt_one! { | ||
fn(&self: RangeFull, _f) -> 1 { | ||
[PanicVal::write_str("..")] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::{FmtArg, PanicFmt, PanicVal}; | ||
|
||
use core::num::{ | ||
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128, | ||
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, | ||
}; | ||
|
||
macro_rules! nonzero_impls { | ||
($(($int_ctor:ident, $ty:ty))*) => ( | ||
$( | ||
primitive_static_panicfmt!{ | ||
fn[](&self: $ty, fmtarg) { | ||
PanicVal::$int_ctor(self.0.get(), fmtarg) | ||
} | ||
} | ||
)* | ||
|
||
impl_for_option!{ | ||
$((for[], 'static, $ty, $ty))* | ||
} | ||
) | ||
} | ||
|
||
nonzero_impls! { | ||
(from_u8, NonZeroU8) | ||
(from_i8, NonZeroI8) | ||
(from_u16, NonZeroU16) | ||
(from_i16, NonZeroI16) | ||
(from_u32, NonZeroU32) | ||
(from_i32, NonZeroI32) | ||
(from_u64, NonZeroU64) | ||
(from_i64, NonZeroI64) | ||
(from_u128, NonZeroU128) | ||
(from_i128, NonZeroI128) | ||
(from_usize, NonZeroUsize) | ||
(from_isize, NonZeroIsize) | ||
} |
Oops, something went wrong.