aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/dev/README.md2
-rw-r--r--docs/dev/style.md54
-rw-r--r--docs/user/manual.adoc4
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```
83After I am done with the fix, I use `cargo xtask install --client-code` to try the new extension for real. 83After I am done with the fix, I use `cargo xtask install --client` to try the new extension for real.
84 84
85If 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. 85If 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.
86I usually just `cargo xtask install --server` and poke changes from my live environment. 86I 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
212Prefer `Default` even it has to be implemented manually. 212Prefer `Default` even it has to be implemented manually.
213 213
214## Functions Over Objects
215
216Avoid creating "doer" objects.
217That is, objects which are created only to execute a single action.
218
219```rust
220// Good
221do_thing(arg1, arg2);
222
223// Not as good
224ThingDoer::new(arg1, arg2).do();
225```
226
227Note that this concerns only outward API.
228When implementing `do_thing`, it might be very useful to create a context object.
229
230```rust
231pub fn do_thing(arg1: Arg1, arg2: Arg2) -> Res {
232 let mut ctx = Ctx { arg1, arg2 }
233 ctx.run()
234}
235
236struct Ctx {
237 arg1: Arg1, arg2: Arg2
238}
239
240impl Ctx {
241 fn run(self) -> Res {
242 ...
243 }
244}
245```
246
247The difference is that `Ctx` is an impl detail here.
248
249Sometimes a middle ground is acceptable if this can save some busywork:
250
251```rust
252ThingDoer::do(arg1, arg2);
253
254pub struct ThingDoer {
255 arg1: Arg1, arg2: Arg2,
256}
257
258impl 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
216Rust 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*. 270Rust 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
241NeoVim 0.5 (not yet released) has built-in language server support. 241NeoVim 0.5 (not yet released) has built-in language server support.
242For a quick start configuration of rust-analyzer, use https://github.com/neovim/nvim-lsp#rust_analyzer[neovim/nvim-lsp]. 242For a quick start configuration of rust-analyzer, use https://github.com/neovim/nvim-lspconfig#rust_analyzer[neovim/nvim-lspconfig].
243Once `neovim/nvim-lsp` is installed, use `+lua require'nvim_lsp'.rust_analyzer.setup({})+` in your `init.vim`. 243Once `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