Skip to main content

validate_topic_name

Function validate_topic_name 

Source
pub fn validate_topic_name(name: &str) -> Result<(), ClientError>
Expand description

Validate that a topic name contains only [a-zA-Z0-9-] characters.

LANCE topic names are restricted to alphanumeric characters and hyphens so that they can be safely embedded in file paths and URL segments on all platforms supported by the server.

§Errors

Returns ClientError::InvalidTopicName when name is empty or contains any character outside [a-zA-Z0-9-].

§Examples

use lnc_client::{ClientError, validate_topic_name};

assert!(validate_topic_name("my-topic").is_ok());
assert!(validate_topic_name("rithmic-actions-v2").is_ok());
assert!(validate_topic_name("topic123").is_ok());
assert!(matches!(
    validate_topic_name("bad topic!"),
    Err(ClientError::InvalidTopicName(_))
));
assert!(matches!(
    validate_topic_name(""),
    Err(ClientError::InvalidTopicName(_))
));