pub struct Object(/* private fields */);
Expand description
A RPSL object.
┌───────────────────────────────────────────────┐
│ Object │
├───────────────────────────────────────────────┤
│ [role] ─── ACME Company │
│ [address] ──┬─ Packet Street 6 │
│ ├─ 128 Series of Tubes │
│ └─ Internet │
│ [email] ─── rpsl-rs@github.com │
│ [nic-hdl] ─── RPSL1-RIPE │
│ [source] ─── RIPE │
└───────────────────────────────────────────────┘
Examples
A role object for the ACME corporation.
let role_acme = Object::new(vec![
Attribute::new("role".parse()?, "ACME Company".parse()?),
Attribute::new("address".parse()?, "Packet Street 6".parse()?),
Attribute::new("address".parse()?, "128 Series of Tubes".parse()?),
Attribute::new("address".parse()?, "Internet".parse()?),
Attribute::new("email".parse()?, "rpsl-rs@github.com".parse()?),
Attribute::new("nic-hdl".parse()?, "RPSL1-RIPE".parse()?),
Attribute::new("source".parse()?, "RIPE".parse()?),
]);
Although creating an Object
from a vector of Attribute
s works, the more idiomatic way
to do it is by using the object!
macro.
assert_eq!(
role_acme,
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";
},
);
Each attribute can be accessed by index.
assert_eq!(role_acme[0], Attribute::new("role".parse()?, "ACME Company".parse()?));
assert_eq!(role_acme[6], Attribute::new("source".parse()?, "RIPE".parse()?));
While specific attribute values can be accessed by name.
assert_eq!(role_acme.get("role"), vec!["ACME Company"]);
assert_eq!(role_acme.get("address"), vec!["Packet Street 6", "128 Series of Tubes", "Internet"]);
assert_eq!(role_acme.get("email"), vec!["rpsl-rs@github.com"]);
assert_eq!(role_acme.get("nic-hdl"), vec!["RPSL1-RIPE"]);
assert_eq!(role_acme.get("source"), vec!["RIPE"]);
The entire object can also be represented as RPSL.
assert_eq!(
role_acme.to_string(),
concat!(
"role: ACME Company\n",
"address: Packet Street 6\n",
"address: 128 Series of Tubes\n",
"address: Internet\n",
"email: rpsl-rs@github.com\n",
"nic-hdl: RPSL1-RIPE\n",
"source: RIPE\n",
"\n"
)
);
Implementations§
source§impl Object
impl Object
sourcepub fn new(attributes: Vec<Attribute>) -> Self
pub fn new(attributes: Vec<Attribute>) -> Self
Create a new RPSL object from a vector of attributes.
Example
let role_acme = Object::new(vec![
Attribute::new("role".parse()?, "ACME Company".parse()?),
Attribute::new("address".parse()?, "Packet Street 6".parse()?),
Attribute::new("address".parse()?, "128 Series of Tubes".parse()?),
Attribute::new("address".parse()?, "Internet".parse()?),
Attribute::new("email".parse()?, "rpsl-rs@github.com".parse()?),
Attribute::new("nic-hdl".parse()?, "RPSL1-RIPE".parse()?),
Attribute::new("source".parse()?, "RIPE".parse()?),
]);
Trait Implementations§
source§impl IntoIterator for Object
impl IntoIterator for Object
source§impl PartialEq<Object> for ObjectView<'_>
impl PartialEq<Object> for ObjectView<'_>
source§impl PartialEq for Object
impl PartialEq for Object
impl Eq for Object
impl StructuralEq for Object
impl StructuralPartialEq for Object
Auto Trait Implementations§
impl RefUnwindSafe for Object
impl Send for Object
impl Sync for Object
impl Unpin for Object
impl UnwindSafe for Object
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more