|
1 | 1 | # Organization |
2 | | - |
3 | | - |
4 | | -<a id="c-reexport"></a> |
5 | | -## Crate root re-exports common functionality (C-REEXPORT) |
6 | | - |
7 | | -Crates `pub use` the most common types for convenience, so that clients do not |
8 | | -have to remember or write the crate's module hierarchy to use these types. |
9 | | - |
10 | | -Re-exporting is covered in more detail in the *The Rust Programming Language* |
11 | | -under [Crates and Modules][reexport]. |
12 | | - |
13 | | -[reexport]: https://doc.rust-lang.org/book/first-edition/crates-and-modules.html#re-exporting-with-pub-use |
14 | | - |
15 | | -### Examples from `serde_json` |
16 | | - |
17 | | -The [`serde_json::Value`] type is the most commonly used type from `serde_json`. |
18 | | -It is a re-export of a type that lives elsewhere in the module hierarchy, at |
19 | | -`serde_json::value::Value`. The [`serde_json::value`][value-mod] module defines |
20 | | -other JSON-value-related things that are not re-exported. For example |
21 | | -[`serde_json::value::Index`] is the trait that defines types that can be used to |
22 | | -index into a `Value` using square bracket indexing notation. The `Index` trait |
23 | | -is not re-exported at the crate root because it would be comparatively rare for |
24 | | -a client crate to need to refer to it. |
25 | | - |
26 | | -[`serde_json::Value`]: https://docs.serde.rs/serde_json/enum.Value.html |
27 | | -[value-mod]: https://docs.serde.rs/serde_json/value/index.html |
28 | | -[`serde_json::value::Index`]: https://docs.serde.rs/serde_json/value/trait.Index.html |
29 | | - |
30 | | -In addition to types, functions can be re-exported as well. In `serde_json` the |
31 | | -[`serde_json::from_str`] function is a re-export of a function from the |
32 | | -[`serde_json::de`] deserialization module, which contains other less common |
33 | | -deserialization-related functionality that is not re-exported. |
34 | | - |
35 | | -[`serde_json::from_str`]: https://docs.serde.rs/serde_json/fn.from_str.html |
36 | | -[`serde_json::de`]: https://docs.serde.rs/serde_json/de/index.html |
37 | | - |
38 | | - |
39 | | -<a id="c-hierarchy"></a> |
40 | | -## Modules provide a sensible API hierarchy (C-HIERARCHY) |
41 | | - |
42 | | -### Examples from Serde |
43 | | - |
44 | | -The `serde` crate is two independent frameworks in one crate - a serialization |
45 | | -half and a deserialization half. The crate is divided accordingly into |
46 | | -[`serde::ser`] and [`serde::de`]. Part of the deserialization framework is |
47 | | -isolated under [`serde::de::value`] because it is a relatively large API surface |
48 | | -that is relatively unimportant, and it would crowd the more common, more |
49 | | -important functionality located in `serde::de` if it were to share the same |
50 | | -namespace. |
51 | | - |
52 | | -[`serde::ser`]: https://docs.serde.rs/serde/ser/index.html |
53 | | -[`serde::de`]: https://docs.serde.rs/serde/de/index.html |
54 | | -[`serde::de::value`]: https://docs.serde.rs/serde/de/value/index.html |
0 commit comments