-
Notifications
You must be signed in to change notification settings - Fork 22
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
Copygen v0.5 #34
Comments
Cast OptionHere is the specification for the upcoming PurposeThe purpose of the cast option is to streamline type conversion and assertion in field-to-field copies. ConceptsThere are three main features in the Go Programming Language Specification that Copygen uses to assign variables to another. FunctionalityTypecasting is not a feature in the Go language. Instead, there are type conversions and type assertions. That said, the main domain of Copygen is to handle field-to-field assignment. This involves assignability, type conversion, and type assertion to assign variables of one type to a variable of another type. AssignabilityThe main Copygen program already handles assignability of fields with identical field names AND types. Copygen alternatives that focus on using solely field names to match are prone to mismatching types, and alternatives that focus on using solely type names to match miss the entire point of using Copygen (or the manual Here is an example of a case that maintains assignable fields (via the // Placeholder represents a basic type.
type Placeholder bool
// Copygen defines the functions that will be generated.
type Copygen interface {
NoMatchBasicAlias(B bool) (B Placeholder)
} In this example, the If this assumption wasn't implemented, then cases such as All this to say that Copygen handles assignability and is only missing direct conversion and assertion options. ConversionType conversion can be fulfilled in Copygen using a AssertabilityType assertion can be used on interfaces to assert an interface into an object of another type. This is another way to transform a field of one type to another when applicable. The reverse — assigning an object to an interface — does not require assertion, but the behavior is still not supported in Copygen without the use of Quality of LifeThere are other functionalities involving type conversion, type assertion, or direct conversion functions that the end user may want to use without requiring a FeaturesInstead of creating a separate option for each of these functionalities, each one can be addressed in a single Here is a list of features the
MatcherThe
Implementation "2" entails implementing an automatcher with casting enabled, or a manual matcher with casting enabled, or both. This would warrant a question on "why there are multiple casting matcher implementations (for each type of matcher)?" That's because casting is a matching modifier (implementation "1") and not a standalone matching operation. In other words,
Implementation
MatcherAs a matching modifier, it's expected that QOLWithout further implementation to the above behavior, users will be expected to include the The following implementation requires clarification of match semantics when ANY matching option is provided: Usage of ANY match option ( How can you specify to use the automatcher with automatic casting by default? One option is to allow comments above the ConfigurationThe other alternative is to implement these options in the setup configuration: Copygen currently supports the # Define how the matcher operates.
matcher:
skip: false # replaces -xm which disables (skips) the matcher step (default: disabled).
cast:
enabled: true # Determines whether automatic casting is applied to matched fields (default: disabled).
depth: 1 # Determines the level at which a type is cast (default: 1). This configuration specifies that any matched fields will perform assignment using automatic "typecasting" at a depth level of one. ModificationWhen a user needs to specify a manual cast, they could do so by applying the option modifier at the function level.
This implementation lets the user to enable casting and modify it. The user can disable casting by specifying a depth-level of 0. Since it's common for the
These modification symbols allow the end user to specify how casting is performed for each function, but do NOT allow the user to specify special rules at the generator level. In other words, the user may enable or disable casting at the generator level, but still want the option applied in special condition for EVERY FUNCTION. How do we address these concerns? In the current implementation, we won't: The user is required to specify special conditions at the function-level. This behavior is consistent with how other options — that invoke special rules to a function's output — defined. This design decision is justified by an expectation of collaboration: Any person should be able to look at a Copygen setup file and predict its output. Declaring special rules at the function-level removes confusion from an output's result. DepthDepth works in a similar manner to the depth feature for the automatcher, but with type conversion steps instead of field depth. For example, type A []string // when cast is disabled, only matches with other A fields
type B A
type Copygen interface {
ZeroDepth([]string) ([]string) // []string = []string
OneDepth([]string) (A) // A([]string) = A
TwoDepth([]string) B // B(A([]string)) = B
...
} This will be implemented if possible with the |
Additional ConfigurationAdditional configuration may be added to allow the user to specify feature flags. matcher:
cast:
enabled: true # Determines whether automatic casting is applied to matched fields (default: disabled).
disabled:
assignObjectInterface: false # Disables assignment of object to interfaces (default: false).
asertInterfaceObject: false # Disables assertion of interface to object (default: false).
convert: false # Disables type conversion (default: false). Must use disable as a default due to zero value semantics. |
Hello, any news? |
@listepo I'm technically homeless, but working on Open Source Software every Monday. This week I plan to work multiple days on Copygen to implement this feature with an incoming updated revision (and any incoming issues). If this is an urgent feature for you, consider sponsoring me and I will make this a first priority over all other work. Otherwise, this feature can be worked around using the |
Thank you |
Version 0.5 will require the following changes.
The following changes are dependent on a third-party.
Status
Started on 3/24/23.
Paused on 3/25/23.
Resumed on 3/26/23.
Paused on 3/27/23.
Resumed on 3/29/23.
Paused on 3/29/23 (Housing Issues).
ETA
This target is under development.
The text was updated successfully, but these errors were encountered: