flow icon indicating copy to clipboard operation
flow copied to clipboard

Allow function implementations to include definition into code docs

Open andrewdavidmackenzie opened this issue 5 years ago • 3 comments

See this, and implement when on stable: https://doc.rust-lang.org/unstable-book/language-features/external-doc.html

#[doc(include = "compare_switch.toml")] #[derive(Debug)] pub struct CompareSwitch;

so that the toml definition file is included into the doc comments of the code and is then in the generated docs.

andrewdavidmackenzie avatar Sep 25 '20 17:09 andrewdavidmackenzie

<------ Target 'code-docs' starting warning: unresolved link to input --> flowstdlib/control/compare_switch/compare_switch.rs:6:1 | 6 | / /// Compare two input values and output different the right hand value at different output route 7 | | /// corresponding to is equal, greater than, greater than or equal, less than or less than or equal. 8 | | /// 9 | | /// ## Include using ... | 15 | | 16 | | #[doc(include = "compare_switch.toml")] | |_______________________________________^ | = note: #[warn(broken_intra_doc_links)] on by default = note: the link appears in this line:

       [[input]]
         ^^^^^

= help: to escape [ and ] characters, add '' before them like \[ or \]

warning: unresolved link to input --> flowstdlib/control/compare_switch/compare_switch.rs:6:1 | 6 | / /// Compare two input values and output different the right hand value at different output route 7 | | /// corresponding to is equal, greater than, greater than or equal, less than or less than or equal. 8 | | /// 9 | | /// ## Include using ... | 15 | | 16 | | #[doc(include = "compare_switch.toml")] | |_______________________________________^ | = note: the link appears in this line:

       [[input]]
         ^^^^^

= help: to escape [ and ] characters, add '' before them like \[ or \]

warning: unresolved link to output --> flowstdlib/control/compare_switch/compare_switch.rs:6:1 | 6 | / /// Compare two input values and output different the right hand value at different output route 7 | | /// corresponding to is equal, greater than, greater than or equal, less than or less than or equal. 8 | | /// 9 | | /// ## Include using ... | 15 | | 16 | | #[doc(include = "compare_switch.toml")] | |_______________________________________^ | = note: the link appears in this line:

       [[output]]
         ^^^^^^

= help: to escape [ and ] characters, add '' before them like \[ or \]

warning: 3 warnings emitted

andrewdavidmackenzie avatar Sep 25 '20 17:09 andrewdavidmackenzie

Works, but you loose all formatting:

function = "CompareSwitch" implementation = "compare_switch.rs"

[[input]] name = "left" type = "Number"

[[input]] name = "right" type = "Number"

[[output]] name = "equal" type = "Number"

[[output]] name = "right-lt" type = "Number"

[[output]] name = "right-lte" type = "Number"

[[output]] name = "right-gt" type = "Number"

[[output]] name = "right-gte" type = "Number"

[[output]] name = "left-lt" type = "Number"

[[output]] name = "left-lte" type = "Number"

[[output]] name = "left-gt" type = "Number"

[[output]] name = "left-gte" type = "Number"

andrewdavidmackenzie avatar Sep 25 '20 17:09 andrewdavidmackenzie

I think the best might be to try and generate the spec from the doc comments? so code and spec is together, and that opens the door for macros to help write the code and generate the doc commennts.

andrewdavidmackenzie avatar Sep 25 '20 17:09 andrewdavidmackenzie