1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#![allow(clippy::useless_conversion)]
#![allow(trivial_numeric_casts)]
use crate::{Error, Result};
use cryptoki_sys::CK_SLOT_ID;
use std::convert::{TryFrom, TryInto};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Slot {
slot_id: CK_SLOT_ID,
}
impl Slot {
pub(crate) fn new(slot_id: CK_SLOT_ID) -> Slot {
Slot { slot_id }
}
pub fn id(&self) -> u64 {
self.slot_id as u64
}
}
impl TryFrom<u64> for Slot {
type Error = Error;
fn try_from(slot_id: u64) -> Result<Self> {
Ok(Self {
slot_id: slot_id.try_into()?,
})
}
}
impl From<Slot> for CK_SLOT_ID {
fn from(slot: Slot) -> Self {
slot.slot_id
}
}