-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add Default where there is no explicit default #184
base: main
Are you sure you want to change the base?
Conversation
@@ -551,35 +551,44 @@ impl TypeSpace { | |||
|
|||
Some("uuid") => { | |||
self.uses_uuid = true; | |||
Ok((TypeEntry::new_builtin("uuid::Uuid", &["Display"]), metadata)) | |||
Ok(( | |||
TypeEntry::new_builtin("uuid::Uuid", &["Default", "Display"]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default Uuid does not seem useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as noted in the commit 5fabb9b
(#184), I am unsure about all of these
TypeEntry::new_builtin("chrono::Date<chrono::offset::Utc>", &["Display"]), | ||
TypeEntry::new_builtin( | ||
"chrono::Date<chrono::offset::Utc>", | ||
&["Default", "Display"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
metadata, | ||
)) | ||
} | ||
|
||
Some("ip") => Ok(( | ||
TypeEntry::new_builtin("std::net::IpAddr", &["Display"]), | ||
TypeEntry::new_builtin("std::net::IpAddr", &["Default", "Display"]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
)] | ||
#[educe(Default)] | ||
pub enum StringEnum { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would this have a default
pub struct ExprString(pub String); | ||
impl std::ops::Deref for ExprString { | ||
type Target = String; | ||
fn deref(&self) -> &String { | ||
&self.0 | ||
} | ||
} | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
#[derive(Clone, Debug, Default, Deserialize, Serialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct ExtentTransform { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for example:, but this type clearly doesn't have a default value in the json spec.
@@ -1,7 +1,9 @@ | |||
use serde::{Deserialize, Serialize}; | |||
#[derive(Clone, Debug, Deserialize, Serialize)] | |||
#[derive(Clone, Debug, Deserialize, Serialize, educe :: Educe)] | |||
#[educe(Default)] | |||
#[serde(untagged)] | |||
pub enum IdOrName { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would this type have a default? I don't get it.
The proposal in #181 is a great idea; this implementation seems pretty divergent from that idea. |
This implementation does solve #181, and attempts to fulfill a basic expectation that data structures in Rust should provide a I am required to add this for my HTTP data structures, because another library demands it. It also seems quite feasible to do, hence this WIP, where only one datatype has no |
Closes #181
There is still one error with progenitor tests (
build_nexus
), naming that https://doc.rust-lang.org/std/net/struct.Ipv4Addr.html and friends do not implementDefault
, so any struct which uses them will fail to deriveDefault
. magiclen/educe#6 shows how this can already be fixed witheduce
, and also how an enhancement toeduce
might be able to make the implementation here less complicated.This also highlights there are no tests here using
format: ipv4
in such a similar way to progenitor'snexus.json
, that should causes failures here.