pub struct Example {
pub info: String,
pub lines: Vec<String>,
pub runs: bool,
pub compiles: bool,
}Expand description
One fenced block of a doc comment, classified by what cargo test --doc does with it.
The distinction matters and is the whole reason the block is modelled rather than
counted: a ```text block is prose in a box, a ```ignore block is a
example that is compiled by nobody, and only a Rust block without ignore is a test.
Fields§
§info: StringThe info string of the fence, as written ("", "no_run", "ignore", "text").
lines: Vec<String>The lines of the block, hidden #-prefixed lines included, as written.
runs: boolCompiled and run by cargo test --doc.
compiles: boolCompiled but not run: no_run, and compile_fail which must fail to compile.
Implementations§
Source§impl Example
impl Example
Sourcepub fn executable(&self) -> bool
pub fn executable(&self) -> bool
Is this block executable evidence — compiled by the toolchain, either run or deliberately not run?
use majordomus_cli::quality::source::Example;
let runs = Example::parse("", &["assert_eq!(1 + 1, 2);".into()]);
assert!(runs.executable());
let ignored = Example::parse("ignore", &["nothing();".into()]);
assert!(!ignored.executable(), "an ignored block is compiled by nobody");Sourcepub fn parse(info: &str, lines: &[String]) -> Self
pub fn parse(info: &str, lines: &[String]) -> Self
Classify a fenced block from its info string and its lines.
The rules are rustdoc’s: a block whose info string is empty, or names only Rust
attributes, is Rust; ignore is neither compiled nor run; no_run and
compile_fail are compiled; anything else (text, json, console) is prose.
use majordomus_cli::quality::source::Example;
assert!(Example::parse("", &["let x = 1;".into()]).runs);
assert!(!Example::parse("text", &["a diagram".into()]).executable());
assert!(Example::parse("no_run", &["serve();".into()]).compiles);
assert!(!Example::parse("no_run", &["serve();".into()]).runs);Sourcepub fn visible_lines(&self) -> Vec<String>
pub fn visible_lines(&self) -> Vec<String>
The lines a reader sees: rustdoc hides a line whose first non-space character is
# followed by a space or nothing.
use majordomus_cli::quality::source::Example;
let e = Example::parse("", &["# use std::fmt;".into(), "let x = 1;".into()]);
assert_eq!(e.visible_lines(), vec!["let x = 1;".to_string()]);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Example
impl<'de> Deserialize<'de> for Example
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Example
Source§impl JsonSchema for Example
impl JsonSchema for Example
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreimpl StructuralPartialEq for Example
Auto Trait Implementations§
impl Freeze for Example
impl RefUnwindSafe for Example
impl Send for Example
impl Sync for Example
impl Unpin for Example
impl UnsafeUnpin for Example
impl UnwindSafe for Example
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.