Skip to content

Commit

Permalink
utility: fix example doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcnamara committed Feb 7, 2025
1 parent 25449bf commit 1da5e03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
11 changes: 9 additions & 2 deletions examples/doc_utility_check_sheet_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ use rust_xlsxwriter::{utility, XlsxError};

fn main() -> Result<(), XlsxError> {
// This worksheet name is valid.
utility::check_sheet_name("2030-01-01")?;
let result = utility::check_sheet_name("2030-01-01")?;

assert!(matches!(result, ()));

// This worksheet name isn't valid due to the forward slashes.
utility::check_sheet_name("2030/01/01")?;
let result = utility::check_sheet_name("2030/01/01");

assert!(matches!(
result,
Err(XlsxError::SheetnameContainsInvalidCharacter(_))
));

Ok(())
}
19 changes: 13 additions & 6 deletions src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,20 +687,27 @@ pub(crate) fn is_valid_range(range: &str) -> bool {
///
/// The following example demonstrates testing for a valid worksheet name.
///
/// ```fail
/// ```
/// # // This code is available in examples/doc_utility_check_sheet_name.rs
/// #
/// # use rust_xlsxwriter::{utility, XlsxError};
/// #
/// fn main() -> Result<(), XlsxError> {
/// # fn main() -> Result<(), XlsxError> {
/// // This worksheet name is valid.
/// utility::check_sheet_name("2030-01-01")?;
/// let result = utility::check_sheet_name("2030-01-01")?;
///
/// assert!(matches!(result, ()));
///
/// // This worksheet name isn't valid due to the forward slashes.
/// utility::check_sheet_name("2030/01/01")?;
/// let result = utility::check_sheet_name("2030/01/01");
///
/// Ok(())
/// }
/// assert!(matches!(
/// result,
/// Err(XlsxError::SheetnameContainsInvalidCharacter(_))
/// # ));
/// #
/// # Ok(())
/// # }
///
pub fn check_sheet_name(name: &str) -> Result<(), XlsxError> {
let error_message = format!("Invalid Excel worksheet name '{name}'");
Expand Down

0 comments on commit 1da5e03

Please sign in to comment.