Closed simon-mo closed 1 year ago
Here is the current generator:
Some required fields (BucketName
, ObjectKey
) don't have a reasonable default value. For example, an empty BucketName
is not a valid bucket name. I'm not sure whether the input type should guarantee that its fields are either valid or optional.
Possible solutions:
derive(Default)
, using the empty valuesAh i see. In this case, I would say either just accepting empty values or add a builder for only the required types should be useful? Adding builders for all types seem like it will blow up the code size.
For simplicity, I choose the first one: use empty values as default.
S3 trait implementation can still assume that the input is valid. It is a logic error if the caller passes invalid input to S3 operation.
After some tries, I find that empty defaults may be very misleading. And there are too many "strong types" which don't have space for an invalid default.
I don't feel good about such changes. So adding builders is the better choice.
Thank you!
Hey @Nugine, what's your thought on fluent style builder? I'm happy to provide a patch if that's okay with you. One minor thing is that I don't quite know off the top of my head if it is possible to make both patterns co-exist in rust with the ownership system.
I'm okay with fluent style builder.
The setters of a fluent style builder can take &mut self
or self
and return the same. I prefer the former personally but we can support both styles.
Currently all the setters have a set_
prefix. It's ok if we add different setters without the prefix, like what aws-sdk-s3
does.
For example:
set_bucket(&mut self, field: BucketName) -> &mut Self
bucket(self, field: BucketName) -> Self
The codegen function is here https://github.com/Nugine/s3s/blob/e8bba54fe291664f73566235354002eb02002a75/codegen/src/dto.rs#L606-L625
BTW the codegen for data structures is some what redundant. I'll refactor it one day.
Thanks for this great project.
Is there a reason that there isn't
#derive[Default]
for the input API types likePutObjectInput
? One of my use case is to test the proxy implementation which requires constructing such object, without default it's very verbose to construct them.