# Add an Element derive macro for building components out of other elements \(\#2643\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 3f4a06f576b8a6e8d196f713761594b58a944754

Requested commit: 3f4a06f576b8a6e8d196f713761594b58a944754

Commit: 3f4a06f576b8a6e8d196f713761594b58a944754

Tree: f0dad640bb0517626885a28ea65688e4e52654fc

Author: Nathan Sobo

Committer: GitHub

## Message

````
Add an Element derive macro for building components out of other elements (#2643)

To turn any struct into a composite element, you can implement a render
method with the following signature:

```rs
fn render<V: View>(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V>;
```

Then add #[derive(Element)] to the struct definition.

This will make it easier to introduce higher-level components that are
expressed in terms of other elements. Instead of calling functions that
return elements, we can now make any struct into an element fairly
easily. The advantage is that we can use method chaining to express
optional state on these components, and they blend in better with other
elements.

cc @mikayla-maki @osiewicz @iamnbutler 

Release Notes:

- N/A
````

## Parents

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

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

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