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
| Type | Description |
|---|---|
SINGLELINE | Simple single-line response |
ADD_ONION | ADD_ONION command response |
AUTHCHALLENGE | SAFECOOKIE authentication challenge |
EVENT | Asynchronous event notification |
GETCONF | GETCONF command response |
GETINFO | GETINFO command response |
MAPADDRESS | MAPADDRESS command response |
ONION_CLIENT_AUTH_VIEW | Onion client auth view response |
PROTOCOLINFO | PROTOCOLINFO 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());