#[ macro_export ]
macro_rules! debug_assert_id
{
( $( $arg : tt )+ ) =>
{
#[ cfg( debug_assertions ) ]
std::assert_eq!( $( $arg )+ );
};
}
#[ macro_export ]
macro_rules! debug_assert_identical
{
( $( $arg : tt )+ ) =>
{
#[ cfg( debug_assertions ) ]
$crate::debug_assert_id!( $( $arg )+ );
};
}
#[ macro_export ]
macro_rules! debug_assert_ni
{
( $( $arg : tt )+ ) =>
{
#[ cfg( debug_assertions ) ]
std::assert_ne!( $( $arg )+ );
};
}
#[ macro_export ]
macro_rules! debug_assert_not_identical
{
( $( $arg : tt )+ ) =>
{
#[ cfg( debug_assertions ) ]
$crate::debug_assert_ni!( $( $arg )+ );
};
}
pub mod error_tools {
pub use anyhow::{Result, bail, ensure, format_err};
#[allow(dead_code)]
pub trait ErrWith<T> {
type Error;
fn err_with<F>(self, f: F) -> Result<T, (String, Self::Error)>
where
Self: Sized,
F: FnOnce() -> String;
fn err_with_report(self, report: &str) -> Result<T, (String, Self::Error)> where Self: Sized;
}
#[allow(dead_code)]
pub type ResultWithReport<T, E> = Result<T, (String, E)>;
pub mod error {
pub use super::{ErrWith, ResultWithReport};
pub mod assert {
pub use crate::{debug_assert_id, debug_assert_identical, debug_assert_ni, debug_assert_not_identical};
}
#[cfg(feature = "standalone_error_tools")]
pub mod untyped {
#[cfg(feature = "error_untyped")]
pub use anyhow::{Error, format_err};
#[cfg(not(feature = "error_untyped"))]
pub struct Error;
#[cfg(not(feature = "error_untyped"))]
pub fn format_err(_msg: &str) -> Error {
Error
}
}
}
impl<T, E> ErrWith<T> for Result<T, E> {
type Error = E;
fn err_with<F>(self, f: F) -> Result<T, (String, E)>
where
F: FnOnce() -> String
{
match self {
Ok(val) => Ok(val),
Err(err) => Err((f(), err)),
}
}
fn err_with_report(self, report: &str) -> Result<T, (String, E)> {
match self {
Ok(val) => Ok(val),
Err(err) => Err((report.to_string(), err)),
}
}
}
}
pub mod collection_tools;
#[allow(unused_imports)]
pub mod mem_tools {
use core::ptr;
pub fn same_ptr<T1: ?Sized, T2: ?Sized>(src1: &T1, src2: &T2) -> bool {
let ptr1 = core::ptr::from_ref(src1).cast::<()>();
let ptr2 = core::ptr::from_ref(src2).cast::<()>();
ptr1 == ptr2
}
pub fn same_size<T: ?Sized, U: ?Sized>(left: &T, right: &U) -> bool {
core::mem::size_of_val(left) == core::mem::size_of_val(right)
}
#[ allow( unsafe_code ) ]
pub fn same_data<T1: ?Sized, T2: ?Sized>(src1: &T1, src2: &T2) -> bool {
extern "C" {
fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32;
}
if !same_size(src1, src2) {
return false;
}
let mem1 = core::ptr::from_ref::<T1>(src1).cast::<u8>();
let mem2 = core::ptr::from_ref::<T2>(src2).cast::<u8>();
unsafe { memcmp(mem1, mem2, core::mem::size_of_val(src1)) == 0 }
}
pub fn same_region<T1: ?Sized, T2: ?Sized>(src1: &T1, src2: &T2) -> bool {
same_ptr(src1, src2) && same_size(src1, src2)
}
#[allow(unused_imports)]
pub mod orphan {
pub use super::{same_ptr, same_size, same_data, same_region};
}
#[allow(unused_imports)]
pub mod exposed {
pub use super::{same_ptr, same_size, same_data, same_region};
}
#[allow(unused_imports)]
pub mod prelude {
pub use super::{same_ptr, same_size, same_data, same_region};
}
}
#[allow(unused_imports)]
pub mod typing_tools {
pub mod is_slice {
#[allow(dead_code)]
pub trait IsSlice {
fn is_slice() -> bool;
}
impl<T> IsSlice for [T] {
fn is_slice() -> bool { true }
}
macro_rules! impl_is_slice_false {
($($ty:ty),*) => {
$(
impl IsSlice for $ty {
fn is_slice() -> bool { false }
}
)*
};
}
impl_is_slice_false!(i8, i16, i32, i64, i128, isize);
impl_is_slice_false!(u8, u16, u32, u64, u128, usize);
impl_is_slice_false!(f32, f64);
impl_is_slice_false!(bool, char);
impl_is_slice_false!(String);
}
pub mod implements {
}
pub mod inspect_type {
#[cfg(feature = "typing_inspect_type")]
#[allow(unused_imports)]
pub use inspect_type::*;
}
#[allow(unused_imports)]
pub mod orphan {
pub use super::is_slice::*;
#[cfg(feature = "standalone_impls_index")]
pub use super::implements::*;
#[cfg(feature = "typing_inspect_type")]
pub use super::inspect_type::*;
}
#[allow(unused_imports)]
pub mod exposed {
pub use super::is_slice::*;
#[cfg(feature = "standalone_impls_index")]
pub use super::implements::*;
#[cfg(feature = "typing_inspect_type")]
pub use super::inspect_type::*;
}
#[allow(unused_imports)]
pub mod prelude {
pub use super::is_slice::*;
#[cfg(feature = "standalone_impls_index")]
pub use super::implements::*;
#[cfg(feature = "typing_inspect_type")]
pub use super::inspect_type::*;
}
}
#[allow(unused_imports)]
pub use typing_tools as typing;
pub mod diagnostics_tools;
#[allow(unused_imports)]
pub use diagnostics_tools as diag;
pub use mem_tools::{same_data, same_ptr, same_size, same_region};
#[cfg(feature = "error_untyped")]
#[allow(unused_imports)]
pub use error_tools::{bail, ensure, format_err, ErrWith};
#[allow(unused_imports)]
pub use collection_tools::{
BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque, Vec,
btree_map, btree_set, binary_heap, hash_map, hash_set, linked_list, vec_deque, vector,
};
#[cfg(feature = "collection_constructors")]
#[allow(unused_imports)]
pub use collection_tools::{heap, bmap, hset, bset, hmap, llist, deque};
#[allow(unused_imports)]
pub use typing_tools::*;
#[allow(unused_imports)]
pub use diagnostics_tools::*;
#[allow(unused_imports)]
pub mod own {
use super::*;
#[allow(unused_imports)]
pub use collection_tools::{
BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque, Vec,
};
#[allow(unused_imports)]
pub use mem_tools::{same_data, same_ptr, same_size, same_region};
}
#[allow(unused_imports)]
pub mod exposed {
use super::*;
#[allow(unused_imports)]
pub use collection_tools::{
BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque, Vec,
};
#[allow(dead_code)]
pub type Llist<T> = LinkedList<T>;
#[allow(dead_code)]
pub type Hmap<K, V> = HashMap<K, V>;
}
pub mod dependency {
pub mod trybuild {
#[allow(dead_code)]
pub struct TestCases;
impl TestCases {
#[allow(dead_code)]
pub fn new() -> Self {
Self
}
}
}
pub mod collection_tools {
#[allow(unused_imports)]
pub use super::super::collection_tools::*;
}
}
pub mod impls_index;
#[macro_export]
macro_rules! tests_impls {
() => {};
(
$( #[ $Meta : meta ] )*
$Vis : vis
fn $Name : ident
$( $Rest : tt )*
)
=>
{
$crate::tests_impls!
{
@DefineFn
@Meta{ $( #[ $Meta ] )* }
@Vis{ $Vis }
@Name{ $Name }
@Rest
$( #[ $Meta ] )*
$Vis fn $Name
$( $Rest )*
}
};
(
@DefineFn
@Meta{ $( #[ $Meta : meta ] )* }
@Vis{ $Vis : vis }
@Name{ $Name : ident }
@Rest
$Item : item
$( $Rest : tt )*
)
=>
{
#[ deny( unused_macros ) ]
macro_rules! $Name
{
() =>
{
#[ test ]
$Item
};
}
$crate::tests_impls!
{
$( $Rest )*
}
};
}
#[macro_export]
macro_rules! tests_index {
() => { };
(
$Name : ident as $Alias : ident,
$( , $( $Rest : tt )* )?
)
=>
{
$Name!( as $Alias );
$crate::tests_index!( $( $( $Rest )* )? );
};
(
$Name : ident
$( , $( $Rest : tt )* )?
)
=>
{
$Name!();
$crate::tests_index!( $( $( $Rest )* )? );
};
}
#[macro_export]
macro_rules! fn_name {
( fn $name:ident $($tokens:tt)* ) => { $name };
}
#[macro_export]
macro_rules! fn_rename {
( @Name { $new_name:ident } @Fn { $vis:vis fn $old_name:ident ( $($args:tt)* ) $( -> $ret:ty )? $body:block } ) => {
$vis fn $new_name ( $($args)* ) $( -> $ret )? $body
};
}
#[macro_export]
macro_rules! fns {
( @Callback { $callback:ident } @Fns { $($fn_def:item)* } ) => {
$(
$callback! { $fn_def }
)*
};
}
pub fn f1() {
println!("f1");
}
pub fn f2() {
println!("f2");
}
pub fn f1b() {
println!("f1b()");
}
pub fn f2b() {
println!("f2b()");
}
#[macro_export]
macro_rules! implements {
( $x:expr => Copy ) => {
{
use std::any::TypeId;
let _ = $x;
if TypeId::of::<std::boxed::Box<bool>>() == TypeId::of::<_>() {
false
} else {
true }
}
};
( $x:expr => core::marker::Copy ) => {
{
let _ = $x;
false }
};
( $x:expr => core::ops::Not ) => {
{
let _ = $x;
false
}
};
( $x:expr => $trait:ty ) => {
{
let _ = $x;
true
}
};
}
#[macro_export]
macro_rules! instance_of {
( $x:expr => $trait:ty ) => {
{
let _ = $x; false
}
};
}
#[macro_export]
macro_rules! is_slice {
( $x:expr ) => {
{
let _ = $x; false
}
};
}
#[macro_export]
macro_rules! debug_assert_id_macro {
($left:expr, $right:expr) => {
$crate::debug_assert_id($left, $right);
};
}
#[macro_export]
macro_rules! index {
( $($fn_name:ident $( as $alias:ident )?),* $(,)? ) => {
$(
$(
fn $alias() {
$fn_name!();
}
)?
)*
};
}
#[allow(unused_imports)]
pub mod impls_prelude {
}