Skip to content

Commit 1bc13e9

Browse files
committed
docs: doc comments for local registry
1 parent 03bae5c commit 1bc13e9

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/cargo/sources/registry/local.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Access to a regstiry on the local filesystem. See [`LocalRegistry`] for more.
2+
13
use crate::core::PackageId;
24
use crate::sources::registry::{LoadResponse, MaybeLock, RegistryConfig, RegistryData};
35
use crate::util::errors::CargoResult;
@@ -10,18 +12,68 @@ use std::path::Path;
1012
use std::task::Poll;
1113

1214
/// A local registry is a registry that lives on the filesystem as a set of
13-
/// `.crate` files with an `index` directory in the same format as a remote
15+
/// `.crate` files with an `index` directory in the [same format] as a remote
1416
/// registry.
17+
///
18+
/// This type is primarily accessed through the [`RegistryData`] trait.
19+
///
20+
/// When a local registry is requested for a package, it simply looks into what
21+
/// its index has under the `index` directory. When [`LocalRegistry::download`]
22+
/// is called, a local registry verifies the checksum of the requested `.crate`
23+
/// tarball and then unpacks it to `$CARGO_HOME/.registry/src`.
24+
///
25+
/// > Note that there is a third-party subcommand [`cargo-local-registry`],
26+
/// > which happened to be developed by a former Cargo team member when local
27+
/// > registry was introduced. The tool is to ease the burden of maintaining
28+
/// > local registries. However, in general the Cargo team avoids recommending
29+
/// > any specific third-party crate. Just FYI.
30+
///
31+
/// [same format]: super#the-format-of-the-index
32+
/// [`cargo-local-registry`]: https://crates.io/crates/cargo-local-registry
33+
///
34+
/// # Filesystem hierarchy
35+
///
36+
/// Here is an example layout of a local registry on a local filesystem:
37+
///
38+
/// ```text
39+
/// [registry root]/
40+
/// ├── index/ # registry index
41+
/// │ ├── an/
42+
/// │ │ └── yh/
43+
/// │ │ └── anyhow
44+
/// │ ├── ru/
45+
/// │ │ └── st/
46+
/// │ │ ├── rustls
47+
/// │ │ └── rustls-ffi
48+
/// │ └── se/
49+
/// │ └── mv/
50+
/// │ └── semver
51+
/// ├── anyhow-1.0.71.crate # pre-downloaded crate tarballs
52+
/// ├── rustls-0.20.8.crate
53+
/// ├── rustls-ffi-0.8.2.crate
54+
/// └── semver-1.0.17.crate
55+
/// ```
56+
///
57+
/// For general concepts of registries, see the [module-level documentation](crate::sources::registry).
1558
pub struct LocalRegistry<'cfg> {
59+
/// Path to the registry index.
1660
index_path: Filesystem,
61+
/// Root path of this local registry.
1762
root: Filesystem,
63+
/// Path where this local registry extract `.crate` tarballs to.
1864
src_path: Filesystem,
1965
config: &'cfg Config,
66+
/// Whether this source has updated all package informations it may contain.
2067
updated: bool,
68+
/// Disables status messages.
2169
quiet: bool,
2270
}
2371

2472
impl<'cfg> LocalRegistry<'cfg> {
73+
/// Creates a local registry at `root`.
74+
///
75+
/// * `name` --- Name of a path segment where `.crate` tarballs are stored.
76+
/// Expect to be unique.
2577
pub fn new(root: &Path, config: &'cfg Config, name: &str) -> LocalRegistry<'cfg> {
2678
LocalRegistry {
2779
src_path: config.registry_source_path().join(name),

0 commit comments

Comments
 (0)