misplib/src/v1/schemas/galaxy_description.rs
2023-07-12 00:21:51 +02:00

43 lines
No EOL
1 KiB
Rust

default_derive!{
pub struct GalaxyDescription {
name: String
}
}
impl TryFrom<&str> for GalaxyDescription {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 65535 {
Ok(GalaxyDescription { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyDescription")
}
}
}
impl Into<String> for GalaxyDescription {
fn into(self) -> String {
self.name
}
}
#[test]
fn oversized() {
let id: Result<GalaxyDescription, _> = format!("{:>65536}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyDescription, _> = "".try_into();
assert_eq!(id, Ok(GalaxyDescription { name: "".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyDescription, _> = "some super long description".try_into();
assert_eq!(id, Ok(GalaxyDescription { name: "some super long description".to_string() }))
}