1#![doc(html_root_url = "https://docs.rs/odds/0.4/")]
31#![cfg_attr(feature="unstable", feature(unboxed_closures, fn_traits))]
32
33#![cfg_attr(not(feature = "std"), no_std)]
34
35#[cfg(not(feature = "std"))]
36extern crate core as std;
37extern crate rawslice;
38extern crate rawpointer;
39extern crate unchecked_index;
40
41mod range;
42#[path = "fix.rs"]
43mod fix_impl;
44pub mod char;
45pub mod string;
46pub mod vec;
47pub mod slice;
48pub mod stride;
49
50pub use crate::fix_impl::Fix;
51pub use crate::fix_impl::fix;
52pub use crate::range::IndexRange;
53
54use crate::std::mem;
55
56pub mod prelude {
58 pub use crate::slice::SliceFind;
59 pub use crate::string::StrExt;
60 pub use crate::string::StrChunksWindows;
61 #[cfg(feature = "std-string")]
62 pub use string::StringExt;
63 #[cfg(feature = "std-vec")]
64 pub use vec::{vec, VecExt};
65 #[doc(no_inline)]
66 pub use crate::IndexRange;
67 #[doc(no_inline)]
68 pub use crate::fix;
69}
70
71#[inline]
73pub unsafe fn raw_byte_repr<T: ?Sized>(ptr: &T) -> &[u8] {
74 std::slice::from_raw_parts(
75 ptr as *const _ as *const u8,
76 mem::size_of_val(ptr),
77 )
78}
79
80#[inline(always)]
81unsafe fn unreachable() -> ! {
82 enum Void { }
83 match *(1 as *const Void) {
84 }
86}
87
88#[inline(always)]
92pub unsafe fn debug_assert_unreachable() -> ! {
93 debug_assert!(false, "Entered unreachable section, this is a bug!");
94 unreachable()
95}
96
97pub fn ref_slice<T>(ptr: &T) -> &[T] {
99 unsafe {
100 std::slice::from_raw_parts(ptr, 1)
101 }
102}
103
104pub fn ref_slice_mut<T>(ptr: &mut T) -> &mut [T] {
106 unsafe {
107 std::slice::from_raw_parts_mut(ptr, 1)
108 }
109}
110
111
112#[test]
113fn test_repr() {
114 unsafe {
115 assert_eq!(raw_byte_repr(&17u8), &[17]);
116 assert_eq!(raw_byte_repr("abc"), "abc".as_bytes());
117 }
118}