convert

Function convert 

Source
pub fn convert(
    response_type: &str,
    message: ControlMessage,
) -> Result<ControlMessage, Error>
Expand description

Converts a control message to a specific response type.

This function validates that a ControlMessage conforms to the expected format for a specific response type. It performs type-specific validation without modifying the message.

§Supported Response Types

TypeDescription
SINGLELINESimple single-line response
ADD_ONIONADD_ONION command response
AUTHCHALLENGESAFECOOKIE authentication challenge
EVENTAsynchronous event notification
GETCONFGETCONF command response
GETINFOGETINFO command response
MAPADDRESSMAPADDRESS command response
ONION_CLIENT_AUTH_VIEWOnion client auth view response
PROTOCOLINFOPROTOCOLINFO command response

§Arguments

  • response_type - The type of response to validate (case-insensitive)
  • message - The control message to validate

§Errors

Returns Error::Protocol if:

  • The response type is not supported
  • The message doesn’t conform to the expected format (for SINGLELINE)

§Example

use stem_rs::response::{ControlMessage, convert};

let msg = ControlMessage::from_str("250 OK\r\n", None, false).unwrap();

// Validate as single-line response
let validated = convert("SINGLELINE", msg.clone()).unwrap();

// Multi-line fails SINGLELINE validation
let multi = ControlMessage::from_str("250-line1\r\n250 line2\r\n", None, false).unwrap();
assert!(convert("SINGLELINE", multi).is_err());