-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
const-oid: factor traits into module (#1301)
Adds a `traits` module containing `AssociatedOid` and `DynAssociatedOid`
- Loading branch information
Showing
2 changed files
with
27 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! Trait definitions. | ||
use crate::ObjectIdentifier; | ||
|
||
/// A trait which associates an OID with a type. | ||
pub trait AssociatedOid { | ||
/// The OID associated with this type. | ||
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 | ||
} | ||
} |