pub fn new<S: Into<String>>(name: S) -> Result<Self> {
        let mut name: String = name.into();
        // Convert non hex index to hex
        let indexation_beginning = "messages/indexation/";
        if name.len() > indexation_beginning.len()
            && &name[0..indexation_beginning.len()] == indexation_beginning
            && hex::decode(&name[indexation_beginning.len()..name.len()]).is_err()
        {
            name = format!(
                "messages/indexation/{}",
                hex::encode(&name[indexation_beginning.len()..name.len()])
            );
        }

        let valid_topics = lazy_static!(
          ["milestones/latest", "milestones/confirmed", "messages", "messages/referenced"].to_vec() => Vec<&str>
        );
        let regexes = lazy_static!(
          [
            Regex::new(r"messages/([A-Fa-f0-9]{64})/metadata").expect("regex failed"),
            Regex::new(r"outputs/([A-Fa-f0-9]{64})(\d{4})").expect("regex failed"),
            // bech32 address
            Regex::new("addresses/(iota|atoi|iot|toi)1[A-Za-z0-9]+/outputs").expect("regex failed"),
            // ED25519 address hex
            Regex::new("addresses/ed25519/([A-Fa-f0-9]{64})/outputs").expect("regex failed"),
            Regex::new(r"messages/indexation/([a-f0-9]{2,128})").expect("regex failed"),
            Regex::new(r"transactions/([A-Fa-f0-9]{64})/included-message").expect("regex failed"),
          ].to_vec() => Vec<Regex>
        );

        if valid_topics.iter().any(|valid| valid == &name) || regexes.iter().any(|re| re.is_match(&name)) {
            let topic = Self(name);
            Ok(topic)
        } else {
            Err(crate::Error::InvalidMqttTopic(name))
        }
    }
/// Creates a new topic and checks if it's valid.
Creates a new topic and checks if it's valid.
Creates a new topic and checks if it ' s valid .
pub fn new<S: Into<String>>(name: S) -> Result<Self> {
        let mut name: String = name.into();
        // Convert non hex index to hex
        let indexation_beginning = "messages/indexation/";
        if name.len() > indexation_beginning.len()
            && &name[0..indexation_beginning.len()] == indexation_beginning
            && hex::decode(&name[indexation_beginning.len()..name.len()]).is_err()
        {
            name = format!(
                "messages/indexation/{}",
                hex::encode(&name[indexation_beginning.len()..name.len()])
            );
        }
        let valid_topics = lazy_static!(
          ["milestones/latest", "milestones/confirmed", "messages", "messages/referenced"].to_vec() => Vec<&str>
        );
        let regexes = lazy_static!(
          [
            Regex::new(r"messages/([A-Fa-f0-9]{64})/metadata").expect("regex failed"),
            Regex::new(r"outputs/([A-Fa-f0-9]{64})(\d{4})").expect("regex failed"),
            // bech32 address
            Regex::new("addresses/(iota|atoi|iot|toi)1[A-Za-z0-9]+/outputs").expect("regex failed"),
            // ED25519 address hex
            Regex::new("addresses/ed25519/([A-Fa-f0-9]{64})/outputs").expect("regex failed"),
            Regex::new(r"messages/indexation/([a-f0-9]{2,128})").expect("regex failed"),
            Regex::new(r"transactions/([A-Fa-f0-9]{64})/included-message").expect("regex failed"),
          ].to_vec() => Vec<Regex>
        );
        if valid_topics.iter().any(|valid| valid == &name) || regexes.iter().any(|re| re.is_match(&name)) {
            let topic = Self(name);
            Ok(topic)
        } else {
            Err(crate::Error::InvalidMqttTopic(name))
        }
    }
pub fn new < S : Into < String > > ( name : S ) -> Result < Self > { let mut name : String = name . into ( ) ; // Convert non hex index to hex let indexation_beginning = " " ; if name . len ( ) > indexation_beginning . len ( ) && & name [ 0 .. indexation_beginning . len ( ) ] == indexation_beginning && hex :: decode ( & name [ indexation_beginning . len ( ) .. name . len ( ) ] ) . is_err ( ) { name = format ! ( " " hex encode ( name [ indexation_beginning len ( ) name len ( ) ] ) ) ; } let valid_topics = lazy_static ! ( [ " " " " " " " " ] to_vec ( ) Vec str ) ; let regexes = lazy_static ! ( [ Regex new ( r"messages/([A-Fa-f0-9]{64})/metadata" ) expect ( " " ) Regex new ( r"outputs/([A-Fa-f0-9]{64})(\d{4})" ) expect ( " " ) // bech32 address Regex new ( " " ) expect ( " " ) // ED25519 address hex Regex new ( " " ) expect ( " " ) Regex new ( r"messages/indexation/([a-f0-9]{2,128})" ) expect ( " " ) Regex new ( r"transactions/([A-Fa-f0-9]{64})/included-message" ) expect ( " " ) ] to_vec ( ) Vec Regex ) ; if valid_topics . iter ( ) . any ( | valid | valid == & name ) || regexes . iter ( ) . any ( | re | re . is_match ( & name ) ) { let topic = Self ( name ) ; Ok ( topic ) } else { Err ( crate :: Error :: InvalidMqttTopic ( name ) ) } }
Creates a new topic and checks if it's valid.
Creates a new topic and checks if it ' s valid .
name
S
name
S