Skip to content

Conversation

@pbrkr
Copy link
Contributor

@pbrkr pbrkr commented Aug 13, 2025

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGELOG.md if knowledge of this change could be valuable to users.

  • Add a Gpx::new() method.
  • Tidy up the examples in the README.md file and run them as doctests to ensure that they remain valid.

@pbrkr pbrkr changed the title Add new method and tidy docs Add new method and tidy examples Aug 13, 2025
@pbrkr pbrkr force-pushed the add-new-method-and-tidy-docs branch 2 times, most recently from 6de9fda to 76ed47c Compare August 13, 2025 09:56
@pbrkr
Copy link
Contributor Author

pbrkr commented Aug 13, 2025

Looks like CI tests are failing due to rust-lang/rustup#4220.

pbrkr added 4 commits August 19, 2025 08:21
This allows simpler instantiation of a new Gpx object.
These changes simplify the example and allow it to be ran as a doctest.

- Use ::new() functions instead of struct literals to make the code
  easier to read.

- Use the tempfile crate so that we can write to a throw-away file.

- Convert the example to a main() function with a simpler function
  signature.

- Re-arrange statements so that we populate the Gpx object first then
  open the output file and write to it.
These changes allow the example to be ran as a doctest.
@michaelkirk michaelkirk force-pushed the add-new-method-and-tidy-docs branch from 76ed47c to 4343e29 Compare August 19, 2025 15:23
Copy link
Member

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I rebased and will merge as soon as tests pass. Thank you!

pub mod errors;

// Ensure that examples in the README are tested
#[doc = include_str!("../README.md")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never seen this before. Love it.

Copy link
Contributor Author

@pbrkr pbrkr Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an example in the docs: https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html#include-items-only-when-collecting-doctests

Another possible use of #[cfg(doctest)] is to test doctests that are included in your README file without including it in your main documentation. For example, you could write this into your lib.rs to test your README as part of your doctests:

#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;

This will include your README as documentation on the hidden struct ReadmeDoctests, which will then be tested alongside the rest of your doctests.

@michaelkirk michaelkirk merged commit 7ad83e3 into georust:master Aug 19, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants