[][src]Function ppp::to_string

pub fn to_string(header: Header) -> Result<String, ()>

Creates a String from a valid Version 1 header. See the protocol specification for the definition of valid text headers.

Examples

TCP4


let text = "PROXY TCP4 127.0.1.2 192.168.1.101 80 443\r\n";
let header = Header::version_1(([127, 0, 1, 2], [192, 168, 1, 101], 80, 443).into());

assert_eq!(ppp::to_string(header), Ok(String::from(text)));

TCP6


let text = "PROXY TCP6 1234:5678:90AB:CDEF:FEDC:BA09:8765:4321 4321:8765:BA09:FEDC:CDEF:90AB:5678:1234 443 65535\r\n";
let header = Header::version_1((
    [0x1234, 0x5678, 0x90AB, 0xCDEF, 0xFEDC, 0xBA09, 0x8765, 0x4321],
    [0x4321, 0x8765, 0xBA09, 0xFEDC, 0xCDEF, 0x90AB, 0x5678, 0x01234],
    443,
    65535,
).into());
assert_eq!(ppp::to_string(header), Ok(String::from(text)));

Invalid Text Header


let header = Header::no_address(Version::Two, Command::Proxy, Protocol::Unspecified);

assert!(ppp::to_string(header).is_err());