patterns/README.md

75 lines
3.1 KiB
Markdown
Raw Normal View History

2015-08-30 22:06:10 +00:00
# Rust Design Patterns
An open source repository of design patterns and idioms in the Rust programming
language.
## Contents
[Introduction](intro.md)
### Idioms
2015-08-31 04:24:23 +00:00
* [Constructor](idioms/ctor.md)
2015-10-15 02:08:29 +00:00
* [Concatenating strings with `format!`](idioms/concat-format.md)
* [Privacy for extensibility](idioms/priv-extend.md)
2016-01-05 21:47:07 +00:00
* TODO stability for extensibility
2015-10-15 06:29:27 +00:00
* TODO trait to separate visibility of methods from visibility of data (https://github.com/sfackler/rust-postgres/blob/master/src/lib.rs#L1400)
* [Collections are smart pointers](idioms/deref.md)
2015-10-15 06:29:27 +00:00
* TODO leak amplification ("Vec::drain sets the Vec's len to 0 prematurely so that mem::forgetting Drain "only" mem::forgets more stuff. instead of exposing uninitialized memory or having to update the len on every iteration")
* [Finalisation in destructors](idioms/dtor-finally.md)
2015-10-15 06:29:27 +00:00
* TODO interior mutability - UnsafeCell, Cell, RefCell
2016-07-25 10:09:26 +00:00
* [Iterating over an `Option`](idioms/option-iter.md)
2016-12-31 13:56:54 +00:00
* [`Default` trait](idioms/default.md)
2016-09-26 06:25:50 +00:00
* [Pass variables to closure](idioms/pass-var-to-closure.md)
2016-10-08 17:14:05 +00:00
* [`mem::replace(_)` to avoid needless clones](idioms/mem-replace.md)
2015-08-30 22:06:10 +00:00
### Design patterns
2015-10-15 02:08:29 +00:00
* [Builder](patterns/builder.md)
* [RAII guards](patterns/RAII.md)
2015-10-15 06:29:27 +00:00
* [Newtype](patterns/newtype.md)
* TODO iterators (to safely avoid bounds checks)
* TODO closures and lifetimes (coupling to lifetime)
* TODO platform-specific sub-modules (https://github.com/rust-lang/rfcs/blob/master/text/0517-io-os-reform.md#platform-specific-opt-in)
2019-01-26 14:01:41 +00:00
* [Entry API](patterns/entry.md) (Currently just a boilerplate)
2015-12-09 01:00:17 +00:00
* [Visitor](patterns/visitor.md)
2016-01-05 21:47:07 +00:00
* [Fold](patterns/fold.md)
2016-09-25 01:37:36 +00:00
* [Prefer small crates](patterns/small-crates.md)
2015-10-15 06:29:27 +00:00
* TODO extension traits
* TODO destructor bombs (ensure linear typing dynamically, e.g., https://github.com/Munksgaard/session-types/commit/0f25ccb7c3bc9f65fa8eaf538233e8fe344a189a)
* TODO convertible to Foo trait for more generic generics (e.g., http://static.rust-lang.org/doc/master/std/fs/struct.File.html#method.open)
* [Late bound bounds](patterns/late-bounds.md)
2015-10-15 06:29:27 +00:00
* TODO 'shadow' borrowed version of struct - e.g., double buffering, Niko's parser generator
* TODO composition of structs to please the borrow checker
* TODO `Error` traits and `Result` forwarding
2015-10-31 17:40:47 +00:00
* TODO graphs
2015-10-19 20:44:24 +00:00
* [Compose structs together for better borrowing](patterns/compose-structs.md)
2015-10-15 02:08:29 +00:00
2015-08-30 22:06:10 +00:00
### Anti-patterns
2015-10-15 06:29:27 +00:00
* TODO thread + catch_panic for exceptions
* TODO Clone to satisfy the borrow checker
2015-10-31 17:40:47 +00:00
* [Deref polymorphism](anti_patterns/deref.md)
2015-10-15 06:29:27 +00:00
* TODO Matching all fields of a struct (back compat)
* TODO wildcard matches
* TODO taking an enum rather than having multiple functions
* TODO `unwrap()`ing every `Result` instead of forwarding it
* [`#[deny(warnings)]`](anti_patterns/deny-warnings.md)
2015-08-30 22:06:10 +00:00
## Contributing
2015-10-15 02:12:37 +00:00
Contributions are very welcome!
2015-08-30 22:06:10 +00:00
You should start with [the template](template.md). Copy it into the appropriate
directory, edit it, and submit a PR. You might not want every section, and you
2015-10-15 02:12:37 +00:00
might want to add extra sections.
We suggest leaving a comment on the [issue tracker](https://github.com/rust-unofficial/patterns/issues)
so that other people don't start working on the same topic.
2015-10-15 02:12:37 +00:00
Correction and elaboration PRs are very welcome.