mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Implement bool_then_to_if
assist
This commit is contained in:
parent
c5942c5284
commit
b7d7dd6163
5 changed files with 241 additions and 3 deletions
|
@ -33,6 +33,7 @@
|
|||
//! ord: eq, option
|
||||
//! derive:
|
||||
//! fmt: result
|
||||
//! bool_impl: option, fn
|
||||
|
||||
pub mod marker {
|
||||
// region:sized
|
||||
|
@ -568,6 +569,19 @@ mod macros {
|
|||
}
|
||||
// endregion:derive
|
||||
|
||||
// region:bool_impl
|
||||
#[lang = "bool"]
|
||||
impl bool {
|
||||
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
|
||||
if self {
|
||||
Some(f())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
// endregion:bool_impl
|
||||
|
||||
pub mod prelude {
|
||||
pub mod v1 {
|
||||
pub use crate::{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue