Skip to content

Commit

Permalink
Clean up gpui docs (zed-industries#4240)
Browse files Browse the repository at this point in the history
This PR does some cleanup of the `gpui` docs, making sure we're linking
things appropriately and following good Rust documentation style.

Release Notes:

- N/A
  • Loading branch information
maxdeviant authored Jan 24, 2024
1 parent 1aa02ac commit c07e416
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 110 deletions.
16 changes: 10 additions & 6 deletions crates/gpui/src/app/async_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl AsyncAppContext {
}

/// Reads the global state of the specified type, passing it to the given callback.
///
/// Panics if no global state of the specified type has been assigned.
/// Returns an error if the `AppContext` has been dropped.
pub fn read_global<G: 'static, R>(&self, read: impl FnOnce(&G, &AppContext) -> R) -> Result<R> {
Expand All @@ -166,7 +167,10 @@ impl AsyncAppContext {
}

/// Reads the global state of the specified type, passing it to the given callback.
/// Similar to [read_global], but returns an error instead of panicking if no state of the specified type has been assigned.
///
/// Similar to [`AsyncAppContext::read_global`], but returns an error instead of panicking
/// if no state of the specified type has been assigned.
///
/// Returns an error if no state of the specified type has been assigned the `AppContext` has been dropped.
pub fn try_read_global<G: 'static, R>(
&self,
Expand Down Expand Up @@ -212,33 +216,33 @@ impl AsyncWindowContext {
self.window
}

/// A convenience method for [WindowContext::update()]
/// A convenience method for [`AppContext::update_window`].
pub fn update<R>(&mut self, update: impl FnOnce(&mut WindowContext) -> R) -> Result<R> {
self.app.update_window(self.window, |_, cx| update(cx))
}

/// A convenience method for [WindowContext::update()]
/// A convenience method for [`AppContext::update_window`].
pub fn update_root<R>(
&mut self,
update: impl FnOnce(AnyView, &mut WindowContext) -> R,
) -> Result<R> {
self.app.update_window(self.window, update)
}

/// A convenience method for [WindowContext::on_next_frame()]
/// A convenience method for [`WindowContext::on_next_frame`].
pub fn on_next_frame(&mut self, f: impl FnOnce(&mut WindowContext) + 'static) {
self.window.update(self, |_, cx| cx.on_next_frame(f)).ok();
}

/// A convenience method for [AppContext::global()]
/// A convenience method for [`AppContext::global`].
pub fn read_global<G: 'static, R>(
&mut self,
read: impl FnOnce(&G, &WindowContext) -> R,
) -> Result<R> {
self.window.update(self, |_, cx| read(cx.global(), cx))
}

/// A convenience method for [AppContext::update_global()]
/// A convenience method for [`AppContext::update_global`].
/// for updating the global state of the specified type.
pub fn update_global<G, R>(
&mut self,
Expand Down
5 changes: 3 additions & 2 deletions crates/gpui/src/app/model_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ impl<'a, T: 'static> ModelContext<'a, T> {
self.model_state.clone()
}

/// Arranges for the given function to be called whenever [ModelContext::notify] or [ViewContext::notify] is called with the given model or view.
/// Arranges for the given function to be called whenever [`ModelContext::notify`] or
/// [`ViewContext::notify`](crate::ViewContext::notify) is called with the given model or view.
pub fn observe<W, E>(
&mut self,
entity: &E,
Expand Down Expand Up @@ -150,7 +151,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
}

/// Arrange for the given function to be invoked whenever the application is quit.
/// The future returned from this callback will be polled for up to [gpui::SHUTDOWN_TIMEOUT] until the app fully quits.
/// The future returned from this callback will be polled for up to [crate::SHUTDOWN_TIMEOUT] until the app fully quits.
pub fn on_app_quit<Fut>(
&mut self,
mut on_quit: impl FnMut(&mut T, &mut ModelContext<T>) -> Fut + 'static,
Expand Down
Loading

0 comments on commit c07e416

Please sign in to comment.