You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to print different words with different colours depending on condition:
println!("operation is {}",if op.success {"successful".bright_green()} else {"failed".bright_red()});
This doesn't work because color is encoded into type of returned wrapper.
I've managed to solve it using:
println!("operation is {}",if op.success {"successful".color(AnsiColors::BrightGreen)} else {"failed".color(AnsiColors::BrightRed)});
But it would be cool to be able to perform such conversion more conveniently, so you don't have to rewrite code that much (function name may be arbitrary):
println!("operation is {}",if op.success {"successful".bright_green().downgrade()// converts statically-known color to common type which stores color as value} else {"failed".bright_red().downgrade()});
The text was updated successfully, but these errors were encountered:
I tried to print different words with different colours depending on condition:
This doesn't work because color is encoded into type of returned wrapper.
I've managed to solve it using:
But it would be cool to be able to perform such conversion more conveniently, so you don't have to rewrite code that much (function name may be arbitrary):
The text was updated successfully, but these errors were encountered: