impl of FcpRequest for Persistence
This commit is contained in:
parent
1e2f32f3d0
commit
6c443784bc
|
@ -106,7 +106,8 @@ pub struct ClientPut {
|
|||
dont_compress: Option<bool>,
|
||||
codecs: Option<Vec<String>>,
|
||||
client_token: Option<String>,
|
||||
persistence: Option<Box<OsStr>>,
|
||||
persistence: Option<Persistence>,
|
||||
target_filename: Option<Box<OsStr>>,
|
||||
early_encode: Option<bool>,
|
||||
upload_ffrom: Option<UploadForm>,
|
||||
target_uri: Option<String>, // cloning uri if does not exists
|
||||
|
@ -192,12 +193,6 @@ impl FcpRequest for ClientPut {
|
|||
}
|
||||
}*/
|
||||
|
||||
pub fn default_unwrap<T: FcpRequest>(fcp_type: Option<&T>) -> String {
|
||||
match fcp_type {
|
||||
Some(val) => val.parse(),
|
||||
None => String::from(""),
|
||||
}
|
||||
}
|
||||
impl FcpRequest for String {
|
||||
fn parse(&self) -> String {
|
||||
self.to_string()
|
||||
|
@ -214,40 +209,6 @@ impl FcpRequest for bool {
|
|||
}
|
||||
}
|
||||
|
||||
impl FcpRequest for VerbosityPut {
|
||||
fn parse(&self) -> String {
|
||||
match self {
|
||||
VerbosityPut::SimpleProgress => 0.to_string(),
|
||||
VerbosityPut::ExpectedHashes => 3.to_string(),
|
||||
VerbosityPut::PutFetchable => 8.to_string(),
|
||||
VerbosityPut::StartedCompressionANDFinishedCompression => 9.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_berbosity_put_parsing() {
|
||||
assert_eq!(default_unwrap::<VerbosityPut>(None), "".to_string());
|
||||
assert_eq!(
|
||||
default_unwrap::<VerbosityPut>(Some(&VerbosityPut::SimpleProgress)),
|
||||
"0".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
default_unwrap::<VerbosityPut>(Some(&VerbosityPut::ExpectedHashes)),
|
||||
"3".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
default_unwrap::<VerbosityPut>(Some(&VerbosityPut::PutFetchable)),
|
||||
"8".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
default_unwrap::<VerbosityPut>(Some(
|
||||
&VerbosityPut::StartedCompressionANDFinishedCompression
|
||||
)),
|
||||
"9".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
pub struct ClientGet {
|
||||
message_name: String,
|
||||
ignore_ds: Option<bool>,
|
||||
|
|
|
@ -24,6 +24,41 @@ pub enum VerbosityPut {
|
|||
PutFetchable,
|
||||
StartedCompressionANDFinishedCompression,
|
||||
}
|
||||
|
||||
impl FcpRequest for VerbosityPut {
|
||||
fn parse(&self) -> String {
|
||||
match self {
|
||||
VerbosityPut::SimpleProgress => 0.to_string(),
|
||||
VerbosityPut::ExpectedHashes => 3.to_string(),
|
||||
VerbosityPut::PutFetchable => 8.to_string(),
|
||||
VerbosityPut::StartedCompressionANDFinishedCompression => 9.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_berbosity_put_parsing() {
|
||||
assert_eq!(default_unwrap::<VerbosityPut>(None), "".to_string());
|
||||
assert_eq!(
|
||||
default_unwrap::<VerbosityPut>(Some(&VerbosityPut::SimpleProgress)),
|
||||
"0".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
default_unwrap::<VerbosityPut>(Some(&VerbosityPut::ExpectedHashes)),
|
||||
"3".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
default_unwrap::<VerbosityPut>(Some(&VerbosityPut::PutFetchable)),
|
||||
"8".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
default_unwrap::<VerbosityPut>(Some(
|
||||
&VerbosityPut::StartedCompressionANDFinishedCompression
|
||||
)),
|
||||
"9".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
pub enum VerbosityGet {
|
||||
SimpleProgress,
|
||||
SendingToNetwork,
|
||||
|
@ -45,6 +80,33 @@ pub enum Persistence {
|
|||
Forever,
|
||||
}
|
||||
|
||||
impl FcpRequest for Persistence {
|
||||
fn parse(&self) -> String {
|
||||
match *self {
|
||||
Persistence::Connection => "connection".to_string(),
|
||||
Persistence::Reboot => "reboot".to_string(),
|
||||
Persistence::Forever => "forever".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_persistence_parsing() {
|
||||
assert_eq!(
|
||||
default_unwrap(Some(&Persistence::Connection)),
|
||||
"connection".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
default_unwrap(Some(&Persistence::Reboot)),
|
||||
"reboot".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
default_unwrap(Some(&Persistence::Forever)),
|
||||
"forever".to_string()
|
||||
);
|
||||
assert_eq!(default_unwrap::<Persistence>(None), "".to_string());
|
||||
}
|
||||
|
||||
pub enum UploadForm {
|
||||
Direct,
|
||||
Disk,
|
||||
|
@ -75,3 +137,9 @@ pub enum Priority {
|
|||
pub trait FcpRequest {
|
||||
fn parse(&self) -> String;
|
||||
}
|
||||
pub fn default_unwrap<T: FcpRequest>(fcp_type: Option<&T>) -> String {
|
||||
match fcp_type {
|
||||
Some(val) => val.parse(),
|
||||
None => String::from(""),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue