Rename IIFE to maybe (#3165)
Too good of an idea to forget Release Notes: - N/A
This commit is contained in:
commit
f67f42779b
7 changed files with 22 additions and 22 deletions
|
@ -942,7 +942,7 @@ async fn create_room(
|
||||||
let live_kit_room = live_kit_room.clone();
|
let live_kit_room = live_kit_room.clone();
|
||||||
let live_kit = session.live_kit_client.as_ref();
|
let live_kit = session.live_kit_client.as_ref();
|
||||||
|
|
||||||
util::async_iife!({
|
util::async_maybe!({
|
||||||
let live_kit = live_kit?;
|
let live_kit = live_kit?;
|
||||||
|
|
||||||
let token = live_kit
|
let token = live_kit
|
||||||
|
|
|
@ -46,7 +46,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
use std::{borrow::Cow, hash::Hash, mem, sync::Arc};
|
use std::{borrow::Cow, hash::Hash, mem, sync::Arc};
|
||||||
use theme::{components::ComponentExt, IconButton, Interactive};
|
use theme::{components::ComponentExt, IconButton, Interactive};
|
||||||
use util::{iife, ResultExt, TryFutureExt};
|
use util::{maybe, ResultExt, TryFutureExt};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
dock::{DockPosition, Panel},
|
dock::{DockPosition, Panel},
|
||||||
item::ItemHandle,
|
item::ItemHandle,
|
||||||
|
@ -1461,7 +1461,7 @@ impl CollabPanel {
|
||||||
|
|
||||||
let text = match section {
|
let text = match section {
|
||||||
Section::ActiveCall => {
|
Section::ActiveCall => {
|
||||||
let channel_name = iife!({
|
let channel_name = maybe!({
|
||||||
let channel_id = ActiveCall::global(cx).read(cx).channel_id(cx)?;
|
let channel_id = ActiveCall::global(cx).read(cx).channel_id(cx)?;
|
||||||
|
|
||||||
let channel = self.channel_store.read(cx).channel_for_id(channel_id)?;
|
let channel = self.channel_store.read(cx).channel_for_id(channel_id)?;
|
||||||
|
@ -1941,7 +1941,7 @@ impl CollabPanel {
|
||||||
let disclosed =
|
let disclosed =
|
||||||
has_children.then(|| !self.collapsed_channels.binary_search(&channel.id).is_ok());
|
has_children.then(|| !self.collapsed_channels.binary_search(&channel.id).is_ok());
|
||||||
|
|
||||||
let is_active = iife!({
|
let is_active = maybe!({
|
||||||
let call_channel = ActiveCall::global(cx)
|
let call_channel = ActiveCall::global(cx)
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.room()?
|
.room()?
|
||||||
|
@ -2791,7 +2791,7 @@ impl CollabPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListEntry::Channel { channel, .. } => {
|
ListEntry::Channel { channel, .. } => {
|
||||||
let is_active = iife!({
|
let is_active = maybe!({
|
||||||
let call_channel = ActiveCall::global(cx)
|
let call_channel = ActiveCall::global(cx)
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.room()?
|
.room()?
|
||||||
|
|
|
@ -20,7 +20,7 @@ use std::future::Future;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use util::channel::ReleaseChannel;
|
use util::channel::ReleaseChannel;
|
||||||
use util::{async_iife, ResultExt};
|
use util::{async_maybe, ResultExt};
|
||||||
|
|
||||||
const CONNECTION_INITIALIZE_QUERY: &'static str = sql!(
|
const CONNECTION_INITIALIZE_QUERY: &'static str = sql!(
|
||||||
PRAGMA foreign_keys=TRUE;
|
PRAGMA foreign_keys=TRUE;
|
||||||
|
@ -57,7 +57,7 @@ pub async fn open_db<M: Migrator + 'static>(
|
||||||
let release_channel_name = release_channel.dev_name();
|
let release_channel_name = release_channel.dev_name();
|
||||||
let main_db_dir = db_dir.join(Path::new(&format!("0-{}", release_channel_name)));
|
let main_db_dir = db_dir.join(Path::new(&format!("0-{}", release_channel_name)));
|
||||||
|
|
||||||
let connection = async_iife!({
|
let connection = async_maybe!({
|
||||||
smol::fs::create_dir_all(&main_db_dir)
|
smol::fs::create_dir_all(&main_db_dir)
|
||||||
.await
|
.await
|
||||||
.context("Could not create db directory")
|
.context("Could not create db directory")
|
||||||
|
|
|
@ -4,7 +4,7 @@ use collections::HashMap;
|
||||||
|
|
||||||
use gpui::{AppContext, AssetSource};
|
use gpui::{AppContext, AssetSource};
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use util::{iife, paths::PathExt};
|
use util::{maybe, paths::PathExt};
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct TypeConfig {
|
struct TypeConfig {
|
||||||
|
@ -42,12 +42,12 @@ impl FileAssociations {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_icon(path: &Path, cx: &AppContext) -> Arc<str> {
|
pub fn get_icon(path: &Path, cx: &AppContext) -> Arc<str> {
|
||||||
iife!({
|
maybe!({
|
||||||
let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
|
let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
|
||||||
|
|
||||||
// FIXME: Associate a type with the languages and have the file's langauge
|
// FIXME: Associate a type with the languages and have the file's langauge
|
||||||
// override these associations
|
// override these associations
|
||||||
iife!({
|
maybe!({
|
||||||
let suffix = path.icon_suffix()?;
|
let suffix = path.icon_suffix()?;
|
||||||
|
|
||||||
this.suffixes
|
this.suffixes
|
||||||
|
@ -61,7 +61,7 @@ impl FileAssociations {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_folder_icon(expanded: bool, cx: &AppContext) -> Arc<str> {
|
pub fn get_folder_icon(expanded: bool, cx: &AppContext) -> Arc<str> {
|
||||||
iife!({
|
maybe!({
|
||||||
let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
|
let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
|
||||||
|
|
||||||
let key = if expanded {
|
let key = if expanded {
|
||||||
|
@ -78,7 +78,7 @@ impl FileAssociations {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_chevron_icon(expanded: bool, cx: &AppContext) -> Arc<str> {
|
pub fn get_chevron_icon(expanded: bool, cx: &AppContext) -> Arc<str> {
|
||||||
iife!({
|
maybe!({
|
||||||
let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
|
let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
|
||||||
|
|
||||||
let key = if expanded {
|
let key = if expanded {
|
||||||
|
|
|
@ -349,19 +349,19 @@ pub fn unzip_option<T, U>(option: Option<(T, U)>) -> (Option<T>, Option<U>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Immediately invoked function expression. Good for using the ? operator
|
/// Evaluates to an immediately invoked function expression. Good for using the ? operator
|
||||||
/// in functions which do not return an Option or Result
|
/// in functions which do not return an Option or Result
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! iife {
|
macro_rules! maybe {
|
||||||
($block:block) => {
|
($block:block) => {
|
||||||
(|| $block)()
|
(|| $block)()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Async Immediately invoked function expression. Good for using the ? operator
|
/// Evaluates to an immediately invoked function expression. Good for using the ? operator
|
||||||
/// in functions which do not return an Option or Result. Async version of above
|
/// in functions which do not return an Option or Result, but async.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! async_iife {
|
macro_rules! async_maybe {
|
||||||
($block:block) => {
|
($block:block) => {
|
||||||
(|| async move { $block })()
|
(|| async move { $block })()
|
||||||
};
|
};
|
||||||
|
@ -434,7 +434,7 @@ mod tests {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
let foo = iife!({
|
let foo = maybe!({
|
||||||
option_returning_function()?;
|
option_returning_function()?;
|
||||||
Some(())
|
Some(())
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,7 +19,7 @@ use std::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use util::{
|
use util::{
|
||||||
async_iife,
|
async_maybe,
|
||||||
fs::remove_matching,
|
fs::remove_matching,
|
||||||
github::{latest_github_release, GitHubLspBinaryVersion},
|
github::{latest_github_release, GitHubLspBinaryVersion},
|
||||||
ResultExt,
|
ResultExt,
|
||||||
|
@ -421,7 +421,7 @@ impl LspAdapter for NextLspAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_cached_server_binary_next(container_dir: PathBuf) -> Option<LanguageServerBinary> {
|
async fn get_cached_server_binary_next(container_dir: PathBuf) -> Option<LanguageServerBinary> {
|
||||||
async_iife!({
|
async_maybe!({
|
||||||
let mut last_binary_path = None;
|
let mut last_binary_path = None;
|
||||||
let mut entries = fs::read_dir(&container_dir).await?;
|
let mut entries = fs::read_dir(&container_dir).await?;
|
||||||
while let Some(entry) = entries.next().await {
|
while let Some(entry) = entries.next().await {
|
||||||
|
|
|
@ -8,7 +8,7 @@ use lsp::LanguageServerBinary;
|
||||||
use smol::fs;
|
use smol::fs;
|
||||||
use std::{any::Any, env::consts, path::PathBuf};
|
use std::{any::Any, env::consts, path::PathBuf};
|
||||||
use util::{
|
use util::{
|
||||||
async_iife,
|
async_maybe,
|
||||||
github::{latest_github_release, GitHubLspBinaryVersion},
|
github::{latest_github_release, GitHubLspBinaryVersion},
|
||||||
ResultExt,
|
ResultExt,
|
||||||
};
|
};
|
||||||
|
@ -106,7 +106,7 @@ impl super::LspAdapter for LuaLspAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_cached_server_binary(container_dir: PathBuf) -> Option<LanguageServerBinary> {
|
async fn get_cached_server_binary(container_dir: PathBuf) -> Option<LanguageServerBinary> {
|
||||||
async_iife!({
|
async_maybe!({
|
||||||
let mut last_binary_path = None;
|
let mut last_binary_path = None;
|
||||||
let mut entries = fs::read_dir(&container_dir).await?;
|
let mut entries = fs::read_dir(&container_dir).await?;
|
||||||
while let Some(entry) = entries.next().await {
|
while let Some(entry) = entries.next().await {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue