Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
benmaddison committed Feb 2, 2024
1 parent e4ee013 commit e2117d9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/obj/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ macro_rules! rpsl_object_class {
$( $attr_type:ident $( ( $attr_rule:tt ) )? ),* $(,)?
],
}
) => {
rpsl_object_class! {
$( #[$doc] )*
$obj {
class: $class,
name: $name,
key: $name,
parser_rule: $rule,
attributes: [
$( $attr_type $( ($attr_rule) )?, )*
],
}
}
};

(
$( #[$doc:meta] )*
$obj:ident {
class: $class:literal,
name: $name:ty,
key: $key:ty,
parser_rule: $rule:pat,
attributes: [
$( $attr_type:ident $( ( $attr_rule:tt ) )? ),* $(,)?
],
}
) => {
$(#[$doc])*
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -114,6 +140,10 @@ macro_rules! rpsl_object_class {
.boxed()
}
}

impl $crate::obj::ObjectKey for $key {
type Class = $obj;
}
}
}
pub(super) use rpsl_object_class;
22 changes: 21 additions & 1 deletion src/obj/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::fmt;
use std::{collections::HashMap, fmt::Display};

use crate::{
attr::{AttributeSeq, AttributeType, RpslAttribute},
Expand Down Expand Up @@ -262,6 +262,26 @@ pub trait RpslObjectClass: Sized {
}
}

/// Interface for per-object primary key indices.
pub trait ObjectKey: Display {
/// The RPSL object class for which `Self` is the key.
type Class: RpslObjectClass;

fn fmt_key(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.fmt(f)
}
}

trait WrappedKey {
fn boxed(self) -> Box<dyn WrappedKey>;
}

impl<T: ObjectKey + 'static> WrappedKey for T {
fn boxed(self) -> Box<dyn WrappedKey> {
Box::new(self)
}
}

// descr attribute is mandatory and single-valued for all objects in terms of
// rfc2622, but is optional and multi-valued in terms of the ripe object template.
//
Expand Down

0 comments on commit e2117d9

Please sign in to comment.