terny 0.2.0

A simple, C-like, ternary operator for cleaner syntax.
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 5.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 245.16 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • KaityyUwU/terny
    45 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • KaitlynEthylia

Github.com/KaitlynEthylia/terny Crates.io/crates/terny Unlicense Docs.rs/terny

A simple ternary operator macro in rust. the iff! macro is the only item exported by this crate, it simply takes three expressions, seperated by ? and :, and expands them info an if else statement.

Usage


iff!( condition
 ? expressionA
 : expressionB );

expands to:

if condition {
    expressionA
} else {
    expressionB
}

It can also be used in assignment:

let value = iff!(condition
 ? expressionA
 : expressionB );

It can also be used inline:

let value = iff!(condition ? exressionA : expressionB);

It may also be nested, although the code starts to look less clean at this point

let value = iff!(conditionA ? iff!(conditionB ? expressionA : expressionB) : expressionC);

Currently using the ? operator within iff is not possible, as there is no way (that I know of) to check for whitespace. This should be changeable once Tracking issue 54725 becomes stable.