mirror of
https://git.intege.rs/xlib/anything
synced 2025-12-05 20:35:02 +00:00
fix Boxed types
This commit is contained in:
11
src/autotraits.rs
Normal file
11
src/autotraits.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
#![allow(suspicious_auto_trait_impls)]
|
||||
|
||||
pub auto trait NotNothing {}
|
||||
impl !NotNothing for super::Nothing {}
|
||||
|
||||
pub auto trait NotAnything {}
|
||||
impl !NotAnything for super::Anything {}
|
||||
|
||||
impl <T> NotNothing for alloc::boxed::Box<T> {}
|
||||
impl <T> NotAnything for alloc::boxed::Box<T> {}
|
||||
|
||||
11
src/lib.rs
11
src/lib.rs
@@ -8,15 +8,14 @@ use alloc::format;
|
||||
use alloc::string::String;
|
||||
use core::fmt::{Debug, Display, Formatter};
|
||||
use core::any::Any;
|
||||
use crate::autotraits::{NotAnything, NotNothing};
|
||||
|
||||
mod autotraits;
|
||||
|
||||
// ==============================
|
||||
// Anything
|
||||
// ==============================
|
||||
|
||||
auto trait NotAnything {}
|
||||
impl !NotAnything for Anything {}
|
||||
|
||||
pub struct Anything {
|
||||
error: Box<dyn DynError>,
|
||||
|
||||
@@ -118,12 +117,11 @@ impl<T: Any + NotAnything + Debug > DynError for T {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ==============================
|
||||
// Anything
|
||||
// Nothing
|
||||
// ==============================
|
||||
|
||||
auto trait NotNothing {}
|
||||
impl !NotNothing for Nothing {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Nothing;
|
||||
@@ -131,4 +129,3 @@ pub struct Nothing;
|
||||
impl<T: NotNothing> From<T> for Nothing {
|
||||
fn from(_: T) -> Self { Nothing }
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,37 @@ pub fn func_3() -> Result<(),Nothing> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func_4() -> Anything {
|
||||
let a= std::io::Error::last_os_error();
|
||||
Anything::from(a)
|
||||
}
|
||||
|
||||
fn func_5() -> Result<(), Anything> {
|
||||
fn func_5a() -> Result<(), Anything> {
|
||||
fn func_5b() -> Result<(), Anything> {
|
||||
fn func_5c() -> Result<(), Anything> {
|
||||
fn func_5d() -> Result<(), Anything> {
|
||||
Err("Hello World")?;
|
||||
Ok(())
|
||||
}
|
||||
func_5d()?;
|
||||
Ok(())
|
||||
}
|
||||
func_5c()?;
|
||||
Ok(())
|
||||
}
|
||||
func_5b()?;
|
||||
Ok(())
|
||||
}
|
||||
func_5a()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test() {
|
||||
println!("{:?}", func_1().unwrap_err());
|
||||
println!("{:?}", func_2().unwrap_err());
|
||||
println!("{:?}", func_3().unwrap_err());
|
||||
println!("func1: {:?}\n", func_1().unwrap_err());
|
||||
println!("func2: {:?}\n", func_2().unwrap_err());
|
||||
println!("func3: {:?}\n", func_3().unwrap_err());
|
||||
println!("func4: {:?}\n", func_4());
|
||||
println!("func5: {:?}\n", func_5().unwrap_err());
|
||||
}
|
||||
Reference in New Issue
Block a user