Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1102c2

Browse files
codexByron
andcommitted
docs: add crate-root doctests
Co-authored-by: Sebastian Thiel <[email protected]>
1 parent 96d86cb commit b1102c2

69 files changed

Lines changed: 1293 additions & 35 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crate-status.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ The top-level crate that acts as hub to all functionality provided by the `gix-*
215215
* [x] handle 'old' form for reading and detect old form
216216
* [x] list
217217
* [ ] edit
218-
* [ ] API documentation
218+
* [x] API documentation
219219
* [ ] Some examples
220220

221221
### gix-actor
@@ -228,7 +228,7 @@ The top-level crate that acts as hub to all functionality provided by the `gix-*
228228
* types to represent hash digests to identify git objects.
229229
* used to abstract over different kinds of hashes, like SHA1 and the upcoming SHA256
230230
* [x] API documentation
231-
* [ ] Some examples
231+
* [x] Some examples
232232

233233
### gix-chunk
234234
* [x] decode the chunk file table of contents and provide convenient API
@@ -267,7 +267,7 @@ The top-level crate that acts as hub to all functionality provided by the `gix-*
267267
* [x] edit trees efficiently and write changes back
268268
- [ ] See if `gix-fs::InternedMap` improves performance.
269269
* [x] API documentation
270-
* [ ] Some examples
270+
* [x] Some examples
271271

272272
### gix-pack
273273
* **packs**
@@ -311,7 +311,7 @@ The top-level crate that acts as hub to all functionality provided by the `gix-*
311311
* [ ] [special handling for networked packs](https://github.com/git/git/blob/89b43f80a514aee58b662ad606e6352e03eaeee4/packfile.c#L949:L949)
312312
* [ ] [detect and retry packed object reading](https://github.com/git/git/blob/89b43f80a514aee58b662ad606e6352e03eaeee4/packfile.c#L1268:L1268)
313313
* [x] API documentation
314-
* [ ] Some examples
314+
* [x] Some examples
315315

316316
### gix-odb
317317
* **loose object store**
@@ -346,7 +346,7 @@ The top-level crate that acts as hub to all functionality provided by the `gix-*
346346
* [ ] support multiple promisor remotes and `extensions.partialClone`
347347
* [ ] make object lookups, maintenance and connectivity checks promisor-aware
348348
* [x] API documentation
349-
* [ ] Some examples
349+
* [x] Some examples
350350

351351
### gix-diff
352352

@@ -461,7 +461,7 @@ A utility crate with types and functionality related to shallow-file handling.
461461
* [x] username expansion for ssh and git urls
462462
* [x] convert URL to string
463463
* [x] API documentation
464-
* [ ] Some examples
464+
* [x] Some examples
465465

466466
### gix-packetline
467467
* [PKT-Line](https://github.com/git/git/blob/master/Documentation/technical/protocol-common.txt#L52:L52)
@@ -474,7 +474,7 @@ A utility crate with types and functionality related to shallow-file handling.
474474
* [x] `Write` with built-in packet line encoding
475475
* [x] `async` support
476476
* [x] API documentation
477-
* [ ] Some examples
477+
* [x] Some examples
478478

479479
### gix-transport
480480
* No matter what we do here, timeouts must be supported to prevent hanging forever and to make interrupts destructor-safe.

gix-actor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include = ["src/**/*", "LICENSE-*"]
1212
rust-version = "1.82"
1313

1414
[lib]
15-
doctest = false
15+
doctest = true
1616

1717
[features]
1818
## Data structures implement `serde::Serialize` and `serde::Deserialize`.

gix-actor/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
//! This crate provides ways of identifying an actor within the git repository both in shared and mutable variants.
22
//!
3+
//! ## Examples
4+
//!
5+
//! ```
6+
//! use gix_actor::{IdentityRef, SignatureRef};
7+
//!
8+
//! let actor = IdentityRef::from_bytes::<()>(b" Taylor Example < [email protected] >")
9+
//! .unwrap()
10+
//! .trim();
11+
//! assert_eq!(actor.name, "Taylor Example");
12+
//! assert_eq!(actor.email, "[email protected]");
13+
//!
14+
//! let signature = SignatureRef::from_bytes::<()>(b"Taylor Example <[email protected]> 1711398853 +0800")
15+
//! .unwrap()
16+
//! .trim();
17+
//! assert_eq!(signature.actor(), actor);
18+
//!
19+
//! let time = signature.time().unwrap();
20+
//! assert_eq!(time.seconds, 1_711_398_853);
21+
//! assert_eq!(time.offset, 8 * 60 * 60);
22+
//!
23+
//! let owned = signature.to_owned().unwrap();
24+
//! let mut out = Vec::new();
25+
//! owned.write_to(&mut out).unwrap();
26+
//! assert_eq!(out, b"Taylor Example <[email protected]> 1711398853 +0800");
27+
//! ```
28+
//!
329
//! ## Feature Flags
430
#![cfg_attr(
531
all(doc, feature = "document-features"),

gix-attributes/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include = ["src/**/*", "LICENSE-*"]
1212
rust-version = "1.82"
1313

1414
[lib]
15-
doctest = false
15+
doctest = true
1616

1717
[features]
1818
## Data structures implement `serde::Serialize` and `serde::Deserialize`.

gix-attributes/src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
//! Parse `.gitattribute` files and provide utilities to match against them.
22
//!
3+
//! ## Examples
4+
//!
5+
//! ```
6+
//! use gix_attributes::search::{MetadataCollection, Outcome};
7+
//! use gix_glob::pattern::Case;
8+
//!
9+
//! let mut search = gix_attributes::Search::default();
10+
//! let mut collection = MetadataCollection::default();
11+
//! search.add_patterns_buffer(
12+
//! b"*.sh text eol=lf",
13+
//! "<memory>".into(),
14+
//! None,
15+
//! &mut collection,
16+
//! true,
17+
//! );
18+
//!
19+
//! let mut out = Outcome::default();
20+
//! out.initialize_with_selection(&collection, ["text", "eol"]);
21+
//! assert!(search.pattern_matching_relative_path("script.sh".into(), Case::Sensitive, Some(false), &mut out));
22+
//!
23+
//! let assignments = out
24+
//! .iter_selected()
25+
//! .map(|m| m.assignment.to_string())
26+
//! .collect::<Vec<_>>();
27+
//! assert_eq!(assignments, vec!["text", "eol=lf"]);
28+
//! ```
29+
//!
330
//! ## Feature Flags
431
#![cfg_attr(
532
all(doc, feature = "document-features"),

gix-bitmap/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rust-version = "1.82"
1212
exclude = ["CHANGELOG.md"]
1313

1414
[lib]
15-
doctest = false
15+
doctest = true
1616
test = true
1717

1818
[dependencies]

gix-bitmap/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
//! An implementation of the shared parts of git bitmaps used in `gix-pack`, `gix-index` and `gix-worktree`.
22
//!
33
//! Note that many tests are performed indirectly by tests in the aforementioned consumer crates.
4+
//!
5+
//! ## Examples
6+
//!
7+
//! ```
8+
//! let encoded = [
9+
//! 0, 0, 0, 64, // 64 bits in total
10+
//! 0, 0, 0, 2, // two u64 words follow
11+
//! 0, 0, 0, 2, 0, 0, 0, 0, // one RLW word with one literal word
12+
//! 0, 0, 0, 0, 0, 0, 0, 21, // literal bits 0, 2 and 4 set
13+
//! 0, 0, 0, 0, // RLW points at the first word
14+
//! ];
15+
//!
16+
//! let (bitmap, rest) = gix_bitmap::ewah::decode(&encoded).unwrap();
17+
//! let mut set_bits = Vec::new();
18+
//! bitmap.for_each_set_bit(|idx| {
19+
//! set_bits.push(idx);
20+
//! Some(())
21+
//! });
22+
//!
23+
//! assert!(rest.is_empty());
24+
//! assert_eq!(bitmap.num_bits(), 64);
25+
//! assert_eq!(set_bits, vec![0, 2, 4]);
26+
//! ```
427
#![deny(rust_2018_idioms, unsafe_code, missing_docs)]
528

629
/// Bitmap utilities for the advanced word-aligned hybrid bitmap

gix-chunk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ include = ["src/**/*", "LICENSE-*"]
1313
rust-version = "1.82"
1414

1515
[lib]
16-
doctest = false
16+
doctest = true
1717
test = false
1818

1919
[dependencies]

gix-chunk/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
//! Low-level access to reading and writing chunk file based formats.
22
//!
33
//! See the [git documentation](https://github.com/git/git/blob/seen/Documentation/technical/chunk-format.txt) for details.
4+
//!
5+
//! ## Examples
6+
//!
7+
//! ```
8+
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
9+
//! use std::io::Write;
10+
//!
11+
//! let mut index = gix_chunk::file::Index::for_writing();
12+
//! index.plan_chunk(*b"OIDF", 4);
13+
//! index.plan_chunk(*b"DATA", 3);
14+
//!
15+
//! let mut out = index.into_write(Vec::new(), 0)?;
16+
//! while let Some(kind) = out.next_chunk() {
17+
//! match kind {
18+
//! [b'O', b'I', b'D', b'F'] => out.write_all(b"abcd")?,
19+
//! [b'D', b'A', b'T', b'A'] => out.write_all(b"xyz")?,
20+
//! _ => unreachable!("planned chunks are known"),
21+
//! }
22+
//! }
23+
//!
24+
//! let data = out.into_inner();
25+
//! let decoded = gix_chunk::file::Index::from_bytes(&data, 0, 2)?;
26+
//! assert_eq!(decoded.data_by_id(&data, *b"OIDF")?, b"abcd");
27+
//! assert_eq!(decoded.data_by_id(&data, *b"DATA")?, b"xyz");
28+
//! # Ok(()) }
29+
//! ```
430
#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
531

632
/// An identifier to describe the kind of chunk, unique within a chunk file, typically in ASCII

0 commit comments

Comments
 (0)