Skip to content

oOp995/returns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

returns

compile now, figure it out later

turning red squiggles into future problems, because sometimes you just want the compiler to shut the fun up

Install

add this to your Cargo.toml

[dependencies]
returns = "0.1.0"

Problem

Image

> cargo run                                                                         

Image

Solution

satisfy compiler now, implement later

fn main() {
    let _ = diagnose::<i32>();
}
pub fn diagnose<T>() -> T 
{
    // ..
    returns::return_shit!()
}

returns::return_shit!() Behaviour

  • panics in debug-mode

cargo run is debug mode by default, if you forget to write the valid return type, it will panic with information about the line you forget to implement

> cargo run

Image

  • compile error in release-mode

return_shit! can not reach production or release versions, because it will trigger compiling error

> cargo run --release

Image

Another solution

returns::return_default!()

pub fn diagnose<T>() -> T 
where 
    T:Default
{
    // ..
    returns::return_default!()
}

but T must implement Default

returns::return_default!() behaviour

  • debug-mode
> cargo run

it will compile normally and returns the <T as Default>::default() value

  • release-mode it will trigger compiling error about the default implementation you forgot to adjust Image

if you insist to use the <T as Default>::default() in release mode you just can use returns::return_default!(force)

pub fn diagnose<T>() -> T 
where 
    T:Default
{
    // ..
    returns::return_default!(force)
}
> and you are all green again, go for it

About

temporary return macros to let the compiler shut the fun up while building

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages