author: David Wong
Building a specification is pretty straight forward. Cargo-spec follows these steps:
The toml parser expects a manifest specification file that follows the following configuration:
/// A specification file contains a specification, as well as sections of (title, text)
#[derive(Serialize, Deserialize, Debug)]
pub struct Specification {
/// information about a specification
pub metadata: Metadata,
/// configuration of the specification
pub config: Config,
/// files to use for the specification's content
pub sections: HashMap<String, String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
/// main template file
pub template: String,
}
/// Metadata about a specification
#[derive(Serialize, Deserialize, Debug)]
pub struct Metadata {
/// Name of the specification
pub name: String,
/// A description
pub description: Option<String>,
/// Version of the spec
pub version: Option<String>,
/// Authors, if any
pub authors: Vec<String>,
}
The structures are deserialized using the toml encoding.
Any placeholder in the template will get replaced by comments extracted from code. The specification manifest file contains the list of these files.
parsing is based on the extension of the file:
#~
#~
//~
for each file listed by the specification manifest, we follow these steps:
//~ spec:startcode
and //~spec:endcode
statements//~ spec:
are specific instructions:
//~ spec:startcode
will print
every line afterwards, up until a //~ spec:endcode
statement~
at the start of the comment,
not including the first one,
is converted to a tab.
This allows us to write //~~ *
for nested list items.