Skip to content

Commit 01a6f11

Browse files
committed
fix(docs): wrap README batched-API code samples for doctest
The README is included via #![doc = include_str!("../README.md")] in src/lib.rs, so every ```rust block becomes a doctest. The three new samples I added under 'Batched APIs' used `?` against bare references that didn't exist in the doctest scope, and weren't wrapped in a fn returning Result. CI on macOS 26 surfaced this as 3 doctest failures at lib.rs lines 725 / 746 / 758. Locally I'd been running `cargo test --tests` which skips doctests, so I missed it. Fix: tag the three samples `rust,no_run` and wrap each in a `# fn example() -> Result<...>` so they compile + propagate ? cleanly. Also stub out `sample` / `filter` / `config` references so the samples no longer reference undefined names. Verified locally with the same command CI runs: cargo test --doc → 158 passed, 0 failed, 9 ignored.
1 parent 04b415e commit 01a6f11

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,11 @@ APIs over the per-element accessor pattern — they collapse `1 + N + 6N`
722722
FFI calls to one round-trip per category and are ~2× faster on a typical
723723
desktop:
724724

725-
```rust
725+
```rust,no_run
726726
use screencapturekit::prelude::*;
727727
use screencapturekit::shareable_content::ContentSnapshot;
728728
729+
# fn example() -> Result<(), Box<dyn std::error::Error>> {
729730
let content = SCShareableContent::get()?;
730731
731732
// One batched FFI per category — every display + window + app + attrs.
@@ -738,26 +739,39 @@ for w in &windows {
738739
println!("{} - {}", app.map(|a| &*a.application_name).unwrap_or(""),
739740
w.title.as_deref().unwrap_or(""));
740741
}
742+
# Ok(())
743+
# }
741744
```
742745

743746
Same idea on a video sample buffer — read every attachment in one CF→Swift
744747
bridge cast instead of one cast per attribute:
745748

746-
```rust
749+
```rust,no_run
750+
# use screencapturekit::cm::CMSampleBuffer;
751+
# fn example(sample: &CMSampleBuffer) {
747752
if let Some(info) = sample.frame_info() {
748753
println!("status={:?} time={:?} content={:?}",
749754
info.frame_status, info.display_time, info.content_rect);
750755
}
756+
# }
751757
```
752758

753759
For screenshot decoding, `bgra_data()` returns the source pixel layout
754760
directly, skipping the per-pixel R↔B swap that `rgba_data()` performs
755761
inside `CGContext.draw`. Use it when uploading to Metal / wgpu / ffmpeg
756762
which all accept BGRA natively:
757763

758-
```rust
759-
let img = SCScreenshotManager::capture_image(&filter, &config)?;
764+
```rust,no_run
765+
# #[cfg(feature = "macos_14_0")]
766+
# fn example(
767+
# filter: &screencapturekit::stream::content_filter::SCContentFilter,
768+
# config: &screencapturekit::stream::configuration::SCStreamConfiguration,
769+
# ) -> Result<(), Box<dyn std::error::Error>> {
770+
use screencapturekit::screenshot_manager::SCScreenshotManager;
771+
let img = SCScreenshotManager::capture_image(filter, config)?;
760772
let pixels = img.bgra_data()?; // ~5% faster than rgba_data() at 1080p
773+
# Ok(())
774+
# }
761775
```
762776

763777
See [`examples/24_batched_apis_showcase.rs`](examples/24_batched_apis_showcase.rs)

0 commit comments

Comments
 (0)