diff options
Diffstat (limited to 'docs')
-rw-r--r-- | docs/dev/README.md | 2 | ||||
-rw-r--r-- | docs/dev/style.md | 54 | ||||
-rw-r--r-- | docs/user/manual.adoc | 4 |
3 files changed, 57 insertions, 3 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md index 90e74f226..abb387e8e 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md | |||
@@ -80,7 +80,7 @@ For this, it is important to have the following in your `settings.json` file: | |||
80 | "rust-analyzer.serverPath": "rust-analyzer" | 80 | "rust-analyzer.serverPath": "rust-analyzer" |
81 | } | 81 | } |
82 | ``` | 82 | ``` |
83 | After I am done with the fix, I use `cargo xtask install --client-code` to try the new extension for real. | 83 | After I am done with the fix, I use `cargo xtask install --client` to try the new extension for real. |
84 | 84 | ||
85 | If I need to fix something in the `rust-analyzer` crate, I feel sad because it's on the boundary between the two processes, and working there is slow. | 85 | If I need to fix something in the `rust-analyzer` crate, I feel sad because it's on the boundary between the two processes, and working there is slow. |
86 | I usually just `cargo xtask install --server` and poke changes from my live environment. | 86 | I usually just `cargo xtask install --server` and poke changes from my live environment. |
diff --git a/docs/dev/style.md b/docs/dev/style.md index 7a64a0d22..8d57fc049 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md | |||
@@ -211,6 +211,60 @@ impl Foo { | |||
211 | 211 | ||
212 | Prefer `Default` even it has to be implemented manually. | 212 | Prefer `Default` even it has to be implemented manually. |
213 | 213 | ||
214 | ## Functions Over Objects | ||
215 | |||
216 | Avoid creating "doer" objects. | ||
217 | That is, objects which are created only to execute a single action. | ||
218 | |||
219 | ```rust | ||
220 | // Good | ||
221 | do_thing(arg1, arg2); | ||
222 | |||
223 | // Not as good | ||
224 | ThingDoer::new(arg1, arg2).do(); | ||
225 | ``` | ||
226 | |||
227 | Note that this concerns only outward API. | ||
228 | When implementing `do_thing`, it might be very useful to create a context object. | ||
229 | |||
230 | ```rust | ||
231 | pub fn do_thing(arg1: Arg1, arg2: Arg2) -> Res { | ||
232 | let mut ctx = Ctx { arg1, arg2 } | ||
233 | ctx.run() | ||
234 | } | ||
235 | |||
236 | struct Ctx { | ||
237 | arg1: Arg1, arg2: Arg2 | ||
238 | } | ||
239 | |||
240 | impl Ctx { | ||
241 | fn run(self) -> Res { | ||
242 | ... | ||
243 | } | ||
244 | } | ||
245 | ``` | ||
246 | |||
247 | The difference is that `Ctx` is an impl detail here. | ||
248 | |||
249 | Sometimes a middle ground is acceptable if this can save some busywork: | ||
250 | |||
251 | ```rust | ||
252 | ThingDoer::do(arg1, arg2); | ||
253 | |||
254 | pub struct ThingDoer { | ||
255 | arg1: Arg1, arg2: Arg2, | ||
256 | } | ||
257 | |||
258 | impl ThingDoer { | ||
259 | pub fn do(arg1: Arg1, arg2: Arg2) -> Res { | ||
260 | ThingDoer { arg1, arg2 }.run() | ||
261 | } | ||
262 | fn run(self) -> Res { | ||
263 | ... | ||
264 | } | ||
265 | } | ||
266 | ``` | ||
267 | |||
214 | ## Avoid Monomorphization | 268 | ## Avoid Monomorphization |
215 | 269 | ||
216 | Rust uses monomorphization to compile generic code, meaning that for each instantiation of a generic functions with concrete types, the function is compiled afresh, *per crate*. | 270 | Rust uses monomorphization to compile generic code, meaning that for each instantiation of a generic functions with concrete types, the function is compiled afresh, *per crate*. |
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index b9d907a4a..575e5866f 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc | |||
@@ -239,8 +239,8 @@ let g:ale_linters = {'rust': ['analyzer']} | |||
239 | ==== nvim-lsp | 239 | ==== nvim-lsp |
240 | 240 | ||
241 | NeoVim 0.5 (not yet released) has built-in language server support. | 241 | NeoVim 0.5 (not yet released) has built-in language server support. |
242 | For a quick start configuration of rust-analyzer, use https://github.com/neovim/nvim-lsp#rust_analyzer[neovim/nvim-lsp]. | 242 | For a quick start configuration of rust-analyzer, use https://github.com/neovim/nvim-lspconfig#rust_analyzer[neovim/nvim-lspconfig]. |
243 | Once `neovim/nvim-lsp` is installed, use `+lua require'nvim_lsp'.rust_analyzer.setup({})+` in your `init.vim`. | 243 | Once `neovim/nvim-lspconfig` is installed, use `+lua require'nvim_lsp'.rust_analyzer.setup({})+` in your `init.vim`. |
244 | 244 | ||
245 | === Sublime Text 3 | 245 | === Sublime Text 3 |
246 | 246 | ||