Improve the context and IKM list APIs
This commit is contained in:
parent
90c8a2aa87
commit
ae19a16531
5 changed files with 83 additions and 16 deletions
|
@ -1,5 +1,13 @@
|
|||
use std::num::NonZeroU64;
|
||||
|
||||
macro_rules! data_ctx_from_iter {
|
||||
($self: ident, $ctx: ident) => {
|
||||
$self {
|
||||
ctx: $ctx.iter().map(|s| s.to_string()).collect(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub struct DataContext {
|
||||
ctx: Vec<String>,
|
||||
}
|
||||
|
@ -12,12 +20,31 @@ impl DataContext {
|
|||
|
||||
impl<const N: usize> From<[&str; N]> for DataContext {
|
||||
fn from(ctx: [&str; N]) -> Self {
|
||||
Self {
|
||||
ctx: ctx.iter().map(|s| s.to_string()).collect(),
|
||||
}
|
||||
data_ctx_from_iter!(Self, ctx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> From<&[&str; N]> for DataContext {
|
||||
fn from(ctx: &[&str; N]) -> Self {
|
||||
data_ctx_from_iter!(Self, ctx)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[&str]> for DataContext {
|
||||
fn from(ctx: &[&str]) -> Self {
|
||||
data_ctx_from_iter!(Self, ctx)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! key_ctx_from_iter {
|
||||
($self: ident, $ctx: ident) => {
|
||||
$self {
|
||||
ctx: $ctx.iter().map(|s| s.to_string()).collect(),
|
||||
periodicity: Some(crate::DEFAULT_KEY_CTX_PERIODICITY),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub struct KeyContext {
|
||||
pub(crate) ctx: Vec<String>,
|
||||
pub(crate) periodicity: Option<u64>,
|
||||
|
@ -48,3 +75,21 @@ impl KeyContext {
|
|||
self.periodicity.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> From<[&str; N]> for KeyContext {
|
||||
fn from(ctx: [&str; N]) -> Self {
|
||||
key_ctx_from_iter!(Self, ctx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> From<&[&str; N]> for KeyContext {
|
||||
fn from(ctx: &[&str; N]) -> Self {
|
||||
key_ctx_from_iter!(Self, ctx)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[&str]> for KeyContext {
|
||||
fn from(ctx: &[&str]) -> Self {
|
||||
key_ctx_from_iter!(Self, ctx)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue