prefer into()
This commit is contained in:
parent
a5ecf19f70
commit
6e0baa138a
6 changed files with 26 additions and 24 deletions
|
|
@ -106,7 +106,7 @@ impl Cli {
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_uri(&self) -> Uri {
|
pub fn get_uri(&self) -> Uri {
|
||||||
Uri::from(self.url.clone())
|
self.url.clone().into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|
|
||||||
|
|
@ -221,8 +221,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn start_upload_works() {
|
fn start_upload_works() {
|
||||||
let client = MockClient::default();
|
let client = MockClient::default();
|
||||||
let uri = sharry::Uri::from(true);
|
let uri = true.into();
|
||||||
let alias_id = sharry::AliasID::from(true);
|
let alias_id = true.into();
|
||||||
|
|
||||||
let share_id = client
|
let share_id = client
|
||||||
.share_create(&uri, &alias_id, NewShareRequest::new("share", 0))
|
.share_create(&uri, &alias_id, NewShareRequest::new("share", 0))
|
||||||
|
|
|
||||||
|
|
@ -153,8 +153,8 @@ mod tests {
|
||||||
|
|
||||||
fn create_uploading(content: &[u8]) -> (Uploading, sharry::ShareID, NamedTempFile) {
|
fn create_uploading(content: &[u8]) -> (Uploading, sharry::ShareID, NamedTempFile) {
|
||||||
let client = MockClient::default();
|
let client = MockClient::default();
|
||||||
let uri = sharry::Uri::from(true);
|
let uri = true.into();
|
||||||
let alias_id = sharry::AliasID::from(true);
|
let alias_id = true.into();
|
||||||
|
|
||||||
let share_id = client
|
let share_id = client
|
||||||
.share_create(&uri, &alias_id, NewShareRequest::new("share", 0))
|
.share_create(&uri, &alias_id, NewShareRequest::new("share", 0))
|
||||||
|
|
@ -273,8 +273,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn upload_works() {
|
fn upload_works() {
|
||||||
let client = MockClient::default();
|
let client = MockClient::default();
|
||||||
let uri = sharry::Uri::from(true);
|
let uri = true.into();
|
||||||
let alias_id = sharry::AliasID::from(true);
|
let alias_id = true.into();
|
||||||
|
|
||||||
let share_id = client
|
let share_id = client
|
||||||
.share_create(&uri, &alias_id, NewShareRequest::new("share", 0))
|
.share_create(&uri, &alias_id, NewShareRequest::new("share", 0))
|
||||||
|
|
@ -310,8 +310,8 @@ mod tests {
|
||||||
.map(|(content, _)| content);
|
.map(|(content, _)| content);
|
||||||
|
|
||||||
let client = MockClient::default();
|
let client = MockClient::default();
|
||||||
let uri = sharry::Uri::from(true);
|
let uri = true.into();
|
||||||
let alias_id = sharry::AliasID::from(true);
|
let alias_id = true.into();
|
||||||
|
|
||||||
let share_id = client
|
let share_id = client
|
||||||
.share_create(&uri, &alias_id, NewShareRequest::new("share", 0))
|
.share_create(&uri, &alias_id, NewShareRequest::new("share", 0))
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,10 @@ use serde::{Deserialize, Serialize};
|
||||||
///
|
///
|
||||||
/// - impl `From<String>` and `Clone` as this is just a String
|
/// - impl `From<String>` and `Clone` as this is just a String
|
||||||
/// - impl `serde` for cachefile handling
|
/// - impl `serde` for cachefile handling
|
||||||
|
/// - impl `Default` while testing for value generation
|
||||||
/// - impl `AsRef<str>` for using in a `ureq` header and hashing support
|
/// - impl `AsRef<str>` for using in a `ureq` header and hashing support
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(test, derive(Default))]
|
||||||
pub struct AliasID(String);
|
pub struct AliasID(String);
|
||||||
|
|
||||||
impl AsRef<str> for AliasID {
|
impl AsRef<str> for AliasID {
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_share(client: &MockClient) -> ShareID {
|
fn add_share(client: &MockClient) -> ShareID {
|
||||||
let share_id = ShareID::from(true);
|
let share_id = true.into();
|
||||||
client
|
client
|
||||||
.insert_share(&share_id, MockShare::default())
|
.insert_share(&share_id, MockShare::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -196,7 +196,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_file(client: &MockClient, share_id: &ShareID) -> FileID {
|
fn add_file(client: &MockClient, share_id: &ShareID) -> FileID {
|
||||||
let file_id = FileID::from(true);
|
let file_id = true.into();
|
||||||
client
|
client
|
||||||
.insert_file(share_id, &file_id, MockFile::default())
|
.insert_file(share_id, &file_id, MockFile::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -207,7 +207,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn insert_share_works() {
|
fn insert_share_works() {
|
||||||
let client = MockClient::default();
|
let client = MockClient::default();
|
||||||
let share_ids: [_; 10] = std::array::from_fn(|_| ShareID::from(true));
|
let share_ids: [_; 10] = std::array::from_fn(|_| true.into());
|
||||||
|
|
||||||
for share_id in share_ids.as_ref() {
|
for share_id in share_ids.as_ref() {
|
||||||
assert!(client.insert_share(share_id, MockShare::default()).is_ok());
|
assert!(client.insert_share(share_id, MockShare::default()).is_ok());
|
||||||
|
|
@ -242,7 +242,7 @@ mod tests {
|
||||||
fn get_share_nex_errors() {
|
fn get_share_nex_errors() {
|
||||||
let client = MockClient::default();
|
let client = MockClient::default();
|
||||||
add_share(&client);
|
add_share(&client);
|
||||||
let share_ids_nex: [_; 10] = std::array::from_fn(|_| ShareID::from(true));
|
let share_ids_nex: [_; 10] = std::array::from_fn(|_| true.into());
|
||||||
|
|
||||||
for share_id_nex in share_ids_nex.as_ref() {
|
for share_id_nex in share_ids_nex.as_ref() {
|
||||||
let res = client.get_share(share_id_nex);
|
let res = client.get_share(share_id_nex);
|
||||||
|
|
@ -256,7 +256,7 @@ mod tests {
|
||||||
fn insert_file_works() {
|
fn insert_file_works() {
|
||||||
let client = MockClient::default();
|
let client = MockClient::default();
|
||||||
let share_id = add_share(&client);
|
let share_id = add_share(&client);
|
||||||
let file_ids: [_; 10] = std::array::from_fn(|_| FileID::from(true));
|
let file_ids: [_; 10] = std::array::from_fn(|_| true.into());
|
||||||
|
|
||||||
for file_id in file_ids.as_ref() {
|
for file_id in file_ids.as_ref() {
|
||||||
assert!(
|
assert!(
|
||||||
|
|
@ -278,7 +278,7 @@ mod tests {
|
||||||
add_share(&client);
|
add_share(&client);
|
||||||
|
|
||||||
let share_id_nex = ShareID::default();
|
let share_id_nex = ShareID::default();
|
||||||
let res = client.insert_file(&share_id_nex, &FileID::from(true), MockFile::default());
|
let res = client.insert_file(&share_id_nex, &true.into(), MockFile::default());
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
assert!(res.unwrap_err().response_contains("can't find share"));
|
assert!(res.unwrap_err().response_contains("can't find share"));
|
||||||
}
|
}
|
||||||
|
|
@ -312,10 +312,10 @@ mod tests {
|
||||||
let client = MockClient::default();
|
let client = MockClient::default();
|
||||||
let share_id = add_share(&client);
|
let share_id = add_share(&client);
|
||||||
add_file(&client, &share_id);
|
add_file(&client, &share_id);
|
||||||
let file_ids_nex: [_; 10] = std::array::from_fn(|_| FileID::from(true));
|
let file_ids_nex: [_; 10] = std::array::from_fn(|_| true.into());
|
||||||
|
|
||||||
for file_id_nex in file_ids_nex.as_ref() {
|
for file_id_nex in file_ids_nex.as_ref() {
|
||||||
let share_id_nex = ShareID::from(true);
|
let share_id_nex = true.into();
|
||||||
let res = client.get_file(&share_id_nex, file_id_nex);
|
let res = client.get_file(&share_id_nex, file_id_nex);
|
||||||
|
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
|
|
|
||||||
|
|
@ -72,9 +72,9 @@ impl CheckID for (&ShareID, &FileID) {
|
||||||
impl From<bool> for Uri {
|
impl From<bool> for Uri {
|
||||||
fn from(value: bool) -> Self {
|
fn from(value: bool) -> Self {
|
||||||
if value {
|
if value {
|
||||||
Self::from(make_valid(VALID_URI))
|
make_valid(VALID_URI).into()
|
||||||
} else {
|
} else {
|
||||||
Self::from(make_invalid(VALID_URI))
|
make_invalid(VALID_URI).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -82,9 +82,9 @@ impl From<bool> for Uri {
|
||||||
impl From<bool> for AliasID {
|
impl From<bool> for AliasID {
|
||||||
fn from(value: bool) -> Self {
|
fn from(value: bool) -> Self {
|
||||||
if value {
|
if value {
|
||||||
Self::from(make_valid(VALID_ALIAS))
|
make_valid(VALID_ALIAS).into()
|
||||||
} else {
|
} else {
|
||||||
Self::from(make_invalid(VALID_ALIAS))
|
make_invalid(VALID_ALIAS).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,9 +92,9 @@ impl From<bool> for AliasID {
|
||||||
impl From<bool> for ShareID {
|
impl From<bool> for ShareID {
|
||||||
fn from(value: bool) -> Self {
|
fn from(value: bool) -> Self {
|
||||||
if value {
|
if value {
|
||||||
Self::from(make_valid(VALID_SHARE))
|
make_valid(VALID_SHARE).into()
|
||||||
} else {
|
} else {
|
||||||
Self::from(make_invalid(VALID_SHARE))
|
make_invalid(VALID_SHARE).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +129,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn default_is_valid() {
|
fn default_is_valid() {
|
||||||
let uri = Uri::default();
|
let uri = Uri::default();
|
||||||
let alias_id = AliasID::from(true); // no `impl Default`
|
let alias_id = AliasID::default();
|
||||||
let share_id = ShareID::default();
|
let share_id = ShareID::default();
|
||||||
let file_id = FileID::default();
|
let file_id = FileID::default();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue