never type
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#![no_std] #![feature(decl_macro)] #![allow(unused)]
|
#![no_std] #![feature(decl_macro)]
|
||||||
|
#![feature(inherent_associated_types)]
|
||||||
|
#![allow(unused, incomplete_features)]
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -22,6 +24,7 @@ pub mod fnv1;
|
|||||||
pub mod pstruct;
|
pub mod pstruct;
|
||||||
pub mod align;
|
pub mod align;
|
||||||
|
|
||||||
|
pub mod never;
|
||||||
//
|
//
|
||||||
// Export Preludes:
|
// Export Preludes:
|
||||||
//
|
//
|
||||||
@@ -53,6 +56,7 @@ pub mod prelude {
|
|||||||
pub use crate::pstruct::struct_offset;
|
pub use crate::pstruct::struct_offset;
|
||||||
pub use crate::pod::{Pod,Mut};
|
pub use crate::pod::{Pod,Mut};
|
||||||
pub use crate::align::Align;
|
pub use crate::align::Align;
|
||||||
|
pub use crate::never::Never;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod public {
|
pub mod public {
|
||||||
|
|||||||
9
sub/core/src/never.rs
Normal file
9
sub/core/src/never.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
pub type Never = <fn()->! as Ret>::Ret;
|
||||||
|
|
||||||
|
trait Ret { type Ret; }
|
||||||
|
impl<R> Ret for fn() -> R {
|
||||||
|
type Ret=R;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_once() {
|
|
||||||
let mut i = 0;
|
|
||||||
for _ in 0..3 {
|
|
||||||
if x::once!() { i+= 1; }
|
|
||||||
if x::once!() { i+= 1; }
|
|
||||||
}
|
|
||||||
assert_eq!(i, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_chain() {
|
|
||||||
let a = 0x1337;
|
|
||||||
let b = [None,None,Some(&a)];
|
|
||||||
let c = [None,Some(&b), None];
|
|
||||||
assert_eq!(0x1337, x::ptr_chain!(&c as *const _, 0x8, 0x10, 0x0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_pattern() {
|
|
||||||
|
|
||||||
let pattern = x::pattern!("E8 ( AA | CC | DD ) E8 ");
|
|
||||||
use x::xpat::Atom::*;
|
|
||||||
let pattern = &[Save(0), Byte(0xE8),
|
|
||||||
Case(2), Byte(0xCC), Break(8),
|
|
||||||
Case(2), Byte(0xAA), Break(5),
|
|
||||||
Case(2), Byte(0xCC), Break(2), Nop, Byte(0xDD), Byte(0xE8)];
|
|
||||||
let buffer: &[u8] = &[ 0xE8, 0xDD, 0xE8 ];
|
|
||||||
|
|
||||||
let mut scanner = x::Scanner::new(buffer, pattern, ..);
|
|
||||||
let mut saves = [0usize;8];
|
|
||||||
|
|
||||||
assert!(scanner.next(&mut saves));
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user