pub fn parse_object(rpsl: &str) -> Result<Object<'_>, ParseError>
Expand description
Parse RPSL into an Object
, borrowing from the source.
role: ACME Company
address: Packet Street 6
address: 128 Series of Tubes
address: Internet
email: rpsl-rs@github.com
nic-hdl: RPSL1-RIPE
source: RIPE
↓
role: ACME Company ◀─────────────── &"role": &"ACME Company"
address: Packet Street 6 ◀──────────── &"address": &"Packet Street 6"
address: 128 Series of Tubes ◀──────── &"address": &"128 Series of Tubes"
address: Internet ◀─────────────────── &"address": &"Internet"
email: rpsl-rs@github.com ◀───────── &"email": &"rpsl-rs@github.com"
nic-hdl: RPSL1-RIPE ◀───────────────── &"nic-hdl": &"RPSL1-RIPE"
source: RIPE ◀─────────────────────── &"source": &"RIPE"
§Errors
Returns a ParseError
if the input is not valid RPSL.
§Examples
let role_acme = "
role: ACME Company
address: Packet Street 6
address: 128 Series of Tubes
address: Internet
email: rpsl-rs@github.com
nic-hdl: RPSL1-RIPE
source: RIPE
";
let parsed = parse_object(role_acme)?;
assert_eq!(
parsed,
object! {
"role": "ACME Company";
"address": "Packet Street 6";
"address": "128 Series of Tubes";
"address": "Internet";
"email": "rpsl-rs@github.com";
"nic-hdl": "RPSL1-RIPE";
"source": "RIPE";
}
);
Values spread over multiple lines can be parsed too.
let multiline_remark = "
remarks: Value 1
Value 2
";
assert_eq!(
parse_object(multiline_remark)?,
object! {
"remarks": "Value 1", "Value 2";
}
);
An attribute that does not have a value is valid.
let without_value = "
as-name: REMARKABLE
remarks:
remarks: ^^^^^^^^^^ nothing here
";
assert_eq!(
parse_object(without_value)?,
object! {
"as-name": "REMARKABLE";
"remarks": "";
"remarks": "^^^^^^^^^^ nothing here";
}
);
The same goes for values containing only whitespace. Since whitespace to the left of a value is trimmed, they are equivalent to no value.
let whitespace_value = "
as-name: REMARKABLE
remarks:
remarks: ^^^^^^^^^^ nothing but hot air (whitespace)
";
assert_eq!(
parse_object(whitespace_value)?,
object! {
"as-name": "REMARKABLE";
"remarks": "";
"remarks": "^^^^^^^^^^ nothing but hot air (whitespace)";
}
);