[wip] doc for sharry module
This commit is contained in:
parent
903fbc3480
commit
2eb651f919
3 changed files with 30 additions and 26 deletions
|
|
@ -159,7 +159,7 @@ impl Cli {
|
||||||
let mut hasher = Blake2b::new().hash_length(16).to_state();
|
let mut hasher = Blake2b::new().hash_length(16).to_state();
|
||||||
|
|
||||||
hasher.update(self.get_uri().as_ref());
|
hasher.update(self.get_uri().as_ref());
|
||||||
hasher.update(self.alias.as_ref());
|
hasher.update(self.alias.as_ref().as_bytes());
|
||||||
|
|
||||||
for chk in sorted(&self.files) {
|
for chk in sorted(&self.files) {
|
||||||
hasher.update(chk.as_ref());
|
hasher.update(chk.as_ref());
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,10 @@ use super::{FileTrait, Uploading};
|
||||||
|
|
||||||
/// Description of an existing, regular file
|
/// Description of an existing, regular file
|
||||||
///
|
///
|
||||||
/// - impl Clone for `clap` compatibility
|
/// - impl `Clone` for `clap` compatibility
|
||||||
/// - impl serde for appstate caching
|
/// - impl `serde` for cachefile handling
|
||||||
/// - impl PartialEq..Ord to handle multiple files given
|
/// - impl `PartialEq..Ord` to handle multiple files given
|
||||||
|
/// - impl `AsRef<[u8]>` for hashing with `blake2b_simd`
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct Checked {
|
pub struct Checked {
|
||||||
/// canonical path to a regular file
|
/// canonical path to a regular file
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,17 @@ use log::{debug, trace};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
/// ID of a public Sharry alias
|
||||||
|
///
|
||||||
|
/// - impl `From<String>` and `Clone` as this is just a String
|
||||||
|
/// - impl `serde` for cachefile handling
|
||||||
|
/// - impl `AsRef<str>` for using in a `ureq` header and hashing support
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AliasID(String);
|
pub struct AliasID(String);
|
||||||
|
|
||||||
impl fmt::Display for AliasID {
|
impl AsRef<str> for AliasID {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn as_ref(&self) -> &str {
|
||||||
f.write_str(&self.0)
|
self.0.as_ref()
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRef<[u8]> for AliasID {
|
|
||||||
fn as_ref(&self) -> &[u8] {
|
|
||||||
self.0.as_bytes()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,7 +24,12 @@ impl From<String> for AliasID {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
/// ID of a Sharry share
|
||||||
|
///
|
||||||
|
/// - impl `From<String>` and `Clone` as this is just a String
|
||||||
|
/// - impl `serde` for cachefile handling
|
||||||
|
/// - impl `Display` for formatting compatibility
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ShareID(String);
|
pub struct ShareID(String);
|
||||||
|
|
||||||
impl fmt::Display for ShareID {
|
impl fmt::Display for ShareID {
|
||||||
|
|
@ -40,7 +44,13 @@ impl From<String> for ShareID {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
/// ID of a file in a Sharry share
|
||||||
|
///
|
||||||
|
/// - impl `Clone` as this is just a String
|
||||||
|
/// - impl `serde` for cachefile handling
|
||||||
|
/// - impl `Display` for formatting compatibility
|
||||||
|
/// - impl `TryFrom<String>` for extracting from matching a "PATCH" uri
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct FileID(String);
|
pub struct FileID(String);
|
||||||
|
|
||||||
impl fmt::Display for FileID {
|
impl fmt::Display for FileID {
|
||||||
|
|
@ -108,18 +118,11 @@ mod tests {
|
||||||
// check AliasID
|
// check AliasID
|
||||||
let _ = AliasID(input.to_owned());
|
let _ = AliasID(input.to_owned());
|
||||||
let aid = AliasID::from(input.to_owned()); // "From" trait
|
let aid = AliasID::from(input.to_owned()); // "From" trait
|
||||||
assert_eq!(
|
|
||||||
aid.to_string(),
|
|
||||||
input,
|
|
||||||
"`impl Display for AliasID` expected: {:?}, got {:?}",
|
|
||||||
input,
|
|
||||||
aid.to_string(),
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
aid.as_ref(),
|
aid.as_ref(),
|
||||||
input.as_bytes(),
|
input,
|
||||||
"`impl AsRef<[u8]> for AliasID` expected: {:?}, got {:?}",
|
"`impl AsRef<str> for AliasID` expected: {:?}, got {:?}",
|
||||||
input.as_bytes(),
|
input,
|
||||||
aid.as_ref(),
|
aid.as_ref(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue