Comments (1)
Considering the value of this.
Summary
With it | Without it |
---|---|
Runtime error on mismatched types | Compilation error on mismatched types |
Need to define extra enum | Don't need to define extra enum |
Don't need to specify params spec for "used what was set last time" for mapping functions -- always set in cmd ctx | May forget specifying "used what was set last time" for mapping functions, and hit runtime error |
With It
Developers
-
Define an enum to name the function keys:
enum MappingFunctions { BucketNameFromBucketState, IamPolicyArnFromIamPolicyState, }
-
Define the mappings:
let mapping_functions = { let mut mapping_functions = MappingFunctions::new(); mapping_functions.insert(BucketNameFromBucketState, S3BucketState::bucket_name); // .. mapping_functions };
Note:
If we want to have a compilation error here, the
MappingFunctions::insert
function needs to have a type parameter that tells it theItem > Params > Field
that the mapping function is for.However, developers use
#[derive(Params)]
to derive the<ItemParams>FieldWiseSpec
, and requiring them to specify something like the following is arduous:MappingFunction::insert<FromType, ToType>(BucketNameFromBucketState, S3BucketState::bucket_name)
-
Pass
MappingFunctions
toCmdCtxBuilder
, for each code instantiation (may be just one):cmd_ctx_builder.with_mapping_functions(mapping_functions);
-
Not have to call
.with_item_params::<TheItem>(..)
in subsequent calls.
Users
- Get runtime error if the mapping function type doesn't match, but it should be caught by tests.
Framework Maintainers
MappingFunctions
map will have magic logic to store the function argument types and return type.- Error reporting when types are mismatched.
Without It
Developers
-
Define the item params spec:
// First execution let s3_object_params_spec = S3ObjectParams::<WebApp>::field_wise_spec() .with_file_path(web_app_path_local) .with_object_key(object_key) .with_bucket_name_from_map(S3BucketState::bucket_name) .build(); // Subsequent executions let s3_object_params_spec = S3ObjectParams::<WebApp>::field_wise_spec() .with_bucket_name_from_map(S3BucketState::bucket_name) .build();
-
Pass the item params spec to
CmdCtxBuilder
, for every separate code instantiation:cmd_ctx_builder .with_item_params::<S3ObjectItem<WebApp>>( item_id!("s3_object"), s3_object_params_spec, )
This is somewhat of an inconvenience, because if this isn't done, the user / developer will have a runtime error, which looks like this:
peace_rt_model::params_specs_mismatch × Item params specs do not match with the items in the flow. help: The following items either have not had a params spec provided previously, or had contained a mapping function, which cannot be loaded from disk. So the params spec needs to be provided to the command context for: * s3_object
When the closure passed to with_*_from_map
doesn't have the argument type specified, or mismatches, the compilation error is still unclear. rust-lang/rust#119888 will allow us to return a useful compilation error.
Users
No runtime error, because it will be caught at compile time.
Framework Maintainers
- Error messages / diagnostics showing which
CmdCtx
is missing which item spec for which field, should be made clear.
from peace.
Related Issues (20)
- `ApplyPlan`: Display plan to the user
- Metrics: Store durations of each item apply.
- Book: Code block line numbers HOT 1
- `ItemId` and other ID newtypes: Reference type by qualified path
- `ItemId`: API design
- Cross Flow `MappingFn`s: Look up value from a different flow within the same profile
- Refactor Scope Builders
- Map `StreamOutcome` into `ItemStreamOutcome`
- Type Parameter Revamp / Simplification
- Allow progress bars to be toggled on/off per command HOT 1
- Remove progress bar rendering artifact on interrupt
- `CliOutput` interrupt feedback HOT 2
- Business Plan
- Remove `Resources`' type state parameter from `Scope`s
- First Cut Of Web UI HOT 3
- `ParamsSpecs`: Make serialized form more concise HOT 1
- Move types to `*_model` and `*_rt_model` crate structure HOT 1
- `CleanCmd` that saves `*ItemState::None` causes Apply out-of-sync error on subsequent invocation
- `Item::apply_dry` is not designed to work with non-existent state
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from peace.