Skip to content

Commit

Permalink
const-oid: add DynAssociatedOid trait (#758)
Browse files Browse the repository at this point in the history
Adds an object safe value-dependent trait which returns an
`ObjectIdentifier` dynamically, with a blanket impl for types which impl
`AssociatedOid`.
  • Loading branch information
tarcieri committed Nov 12, 2022
1 parent 4b0be5c commit cbcddd2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions const-oid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ pub trait AssociatedOid {
const OID: ObjectIdentifier;
}

/// A trait which associates a dynamic, `&self`-dependent OID with a type,
/// which may change depending on the type's value.
///
/// This trait is object safe and auto-impl'd for any types which impl
/// [`AssociatedOid`].
pub trait DynAssociatedOid {
/// Get the OID associated with this value.
fn oid(&self) -> ObjectIdentifier;
}

impl<T: AssociatedOid> DynAssociatedOid for T {
fn oid(&self) -> ObjectIdentifier {
T::OID
}
}

/// Object identifier (OID).
///
/// OIDs are hierarchical structures consisting of "arcs", i.e. integer
Expand Down

0 comments on commit cbcddd2

Please sign in to comment.