qiniu_upload_manager/data_source/
source_key.rs

1use digest::{generic_array::GenericArray, Digest};
2use sha1::Sha1;
3use std::{
4    fmt::{self, Debug},
5    ops::Deref,
6};
7
8/// 数据源 KEY
9///
10/// 用于区分不同的数据源
11pub struct SourceKey<A: Digest = Sha1>(GenericArray<u8, A::OutputSize>);
12
13impl<A: Digest> SourceKey<A> {
14    /// 创建数据源 KEY
15    #[inline]
16    pub fn new(array: impl Into<GenericArray<u8, A::OutputSize>>) -> Self {
17        Self::from(array.into())
18    }
19}
20
21impl<A: Digest> Deref for SourceKey<A> {
22    type Target = GenericArray<u8, A::OutputSize>;
23
24    fn deref(&self) -> &Self::Target {
25        &self.0
26    }
27}
28
29impl<A: Digest> From<GenericArray<u8, A::OutputSize>> for SourceKey<A> {
30    #[inline]
31    fn from(array: GenericArray<u8, A::OutputSize>) -> Self {
32        Self(array)
33    }
34}
35
36impl<A: Digest> Debug for SourceKey<A> {
37    #[inline]
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        f.debug_tuple("SourceKey").field(&self.0).finish()
40    }
41}
42
43impl<A: Digest> Clone for SourceKey<A> {
44    #[inline]
45    fn clone(&self) -> Self {
46        Self(self.0.clone())
47    }
48}