# WIP: Return WindowHandle\<V: View\> from AppContext::add_window \(\#2820\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/d3c1966d964a202bd965508eb31ef8632f7f689f)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: d3c1966d964a202bd965508eb31ef8632f7f689f

Requested commit: d3c1966d964a202bd965508eb31ef8632f7f689f

Commit: d3c1966d964a202bd965508eb31ef8632f7f689f

Tree: 1c02f645fae5bb1b79a0e8583c507446db63772b

Author: Nathan Sobo

Committer: GitHub

## Message

````
WIP: Return WindowHandle<V: View> from AppContext::add_window (#2820)

Instead of returning a usize for the window id, I'm instead returning a
`WindowHandle<V: View>` where `V` is the type of the window's root view.
@as-cii helped me with a cool technique using generic associated types
where methods on `WindowHandle` can return either T or Option<T>
depending on the `BorrowWindowContext::Result` associated type.

Some example usage...

```rs
let window = cx.add_window(|cx| MyView::new(cx));
let my_view = window.root(cx); // If cx is TestAppContext, returns MyView. Otherwise returns Option<MyView>, because the window could be closed.
```


This isn't insanely beneficial on its own, but I think it will help
clean up our testing story. I'm planning on making `window` more useful
in tests for laying out elements, etc.

- [x] Rework tests that call `add_window` 😅 to expect only a window in
return.
- [x] Get tests passing
- [x] 🚬  test
````

## Parents

- [ee1b4a52cc41cb7c331ad9936f1c1cbfb220057e](https://git.cafe/gitcafe/zed/commit/ee1b4a52cc41cb7c331ad9936f1c1cbfb220057e?format=markdown)

- [2d96388be369259c5e8b6006bfe81cfe979889a3](https://git.cafe/gitcafe/zed/commit/2d96388be369259c5e8b6006bfe81cfe979889a3?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/d3c1966d964a202bd965508eb31ef8632f7f689f?format=markdown)
