Skip to content

Package Format

mafried edited this page Oct 11, 2023 · 18 revisions

Fields

The package format uses JSON syntax and contains the following elements:

Package:

  • name: The package name (type: String).
  • version: The package version (type: String, format: semantic versioning).
  • crates: The crates defined in this package. Crates reflect the structure of corresponding Rust crates (type: Dictionary of Crate objects (key: crate name, value: Crate object)).

Crate:

  • types: Types defined in this crate (type: Dictionary of Type objects (key: type name, value: Type object)).
  • modules: Modules defined in this crate. Modules reflect the structure of corresponding module crates (type: Dictionary of Module objects (key: module name, value: Module object)).

Module:

  • types: Types defined in this module (type: Dictionary of Type objects (key: type name, value: Type object)).
  • modules: Modules defined in this module (type: Dictionary of Module objects (key: module name, value: Module object)).

Type:

  • inputs: Optional list of input edges. If the type implements the Node trait, this needs to be set (type: List of Strings).
  • outputs: Optional list of output edges. If the type implements the Node trait, this needs to be set (type: List of Strings).
  • type_parameters: Optional list of type parameters in case the type is generic (type: List of Strings).
  • constructors: Constructors that can be used to create an instance of this type (type: Dictionary (key: constructor name, value: Constructor object)).

Constructor:

Reflects the flowrs_build::package::Constructor enumeration. Describes in detail how code for constructor function should be created. The necessary fields depend on the enumeration type. Currently, the following types exist:

New

A simple constructor function without any parameters.

  • function_name: The optional name of the constructor function. Default: "new" (type: String).

NewWithObeserver

A simple constructor function with a single parameter being the globally available ChangeObserver object.

  • function_name: The optional name of the constructor function. Default: "new" (type: String).

Example:

"DebugNode":{
  ...
   "constructors":{
      "New":{
         "NewWithObserver":{
         
         }
      }
   }
}

NewWithObserverAndContext

A simple constructor function with two parameters: The globally available ChangeObserver and Context objects.

  • function_name: The optional name of the constructor function. Default: "new" (type: String).

NewWithArbitraryArgs

A constructor with arbitrary arguments.

  • function_name: The optional name of the constructor function. Default: "new" (type: String).
  • arguments: The arguments of the constructor function (type: List of Argument objects).

Argument:

  • name: The name of the argument (type: String).
  • type: The argument type (type: ArgumentType)
  • passing: Describes how the argument is passed to the constructor function (type: ArgumentPassing)
  • construction: Describes how the argument is constructed (type: ArgumentConstruction)

ArgumentPassing: Enumeration

  • Move
  • Clone
  • MutableReference
  • Reference

ArgumentConstruction: Enumeration

  • ExistingObject: One of the global objects (change_observer, context).
  • Constructor: Name of the constructor to use for argument construction (type: String).

ArgumentType: Enumeration

  • Type: A specific type (that can have additional type parameters).
    • name: Name of the type (type: String).
    • type_parameters: Optional list of type parameters (type: List of ArgumentType objects).
  • Generic: A generic type (that can have additional type parameters).
    • name: Name of the type (type: String).
    • type_parameters: Optional list of type parameters (type: List of ArgumentType objects).

Example:

"ValueNode":{
    "inputs":[
        
    ],
    "outputs":[
        "output"
    ],
    "type_parameters":[
        "I"
    ],
    "constructors":{
        "New":{
            "NewWithArbitraryArgs":{
            "arguments":[
                {
                    "type":{
                        "Generic":{
                        "name":"I"
                        }
                    },
                    "name":"value",
                    "passing":"Move",
                    "construction":{
                        "Constructor":"Json"
                    }
                },
                {
                    "type":{
                        "Type":{
                        "name":"()"
                        }
                    },
                    "name":"change_observer",
                    "passing":"Clone",
                    "construction":{
                        "ExistingObject":[
                        
                        ]
                    }
                }
            ]
            }
        }
    }
}

FromJson

A constructor that reads its arguments from JSON. The JSON is part of the flow project JSON.

Example:

"TimerNodeConfig":{
   "constructors":{
      "Json":"FromJson"
   }
}

FromDefault

A constructor that reads its arguments from JSON. The JSON is part of the flow project JSON.

Example:

"TimerNodeConfig":{
   "constructors":{
      "Default":"FromDefault"
   }
}

FromCode

A constructor that is directly written in Rust code.

  • code_template: The code that should be emitted for this constructor. The code can contain placeholders (marked with {{placeholder}}) that are replaced during code generation (type: String).

Possible placeholders:

  • fully_qualified_name: The fully qualified name of the object that should be created.
  • type_name: The name of the type.
  • type_parameter_part: The type parameter part of generic types.
  • type_parameter_NAME: The chosen type for type parameter NAME.
  • mutable: If the object to be created should be mutable, this field contains "mut". If not, it contains "".

Example:

"MyType":{
   "type_parameters":[
      "U",
      "T"
   ],
   "constructors":{
      "Code":{
         "FromCode":{
            "code_template":"let {{fully_qualified_name}}:{{type_parameter_U}} = 5;"
         }
      }
   }
}

Example

{
   "name":"flowrs-std",
   "version":"1.0.0",
   "crates":{
      "flowrs_std":{
         "types":{
            
         },
         "modules":{
            "nodes":{
               "types":{
                  
               },
               "modules":{
                  "debug":{
                     "modules":{
                        
                     },
                     "types":{
                        "DebugNode":{
                           "inputs":[
                              "input"
                           ],
                           "outputs":[
                              "output"
                           ],
                           "type_parameters":[
                              "I"
                           ],
                           "constructors":{
                              "New":{
                                 "NewWithObserver":{
                                    
                                 }
                              }
                           }
                        }
                     }
                  },
                  "value":{
                     "modules":{
                        
                     },
                     "types":{
                        "ValueType":{
                           "constructors":{
                              "Json":"FromJson"
                           }
                        },
                        "ValueNode":{
                           "inputs":[
                              
                           ],
                           "outputs":[
                              "output"
                           ],
                           "type_parameters":[
                              "I"
                           ],
                           "constructors":{
                              "New":{
                                 "NewWithArbitraryArgs":{
                                    "arguments":[
                                       {
                                          "type":{
                                             "Generic":{
                                                "name":"I"
                                             }
                                          },
                                          "name":"value",
                                          "passing":"Move",
                                          "construction":{
                                             "Constructor":"Json"
                                          }
                                       },
                                       {
                                          "type":{
                                             "Type":{
                                                "name":"()"
                                             }
                                          },
                                          "name":"change_observer",
                                          "passing":"Clone",
                                          "construction":{
                                             "ExistingObject":[
                                                
                                             ]
                                          }
                                       }
                                    ]
                                 }
                              }
                           }
                        }
                     }
                  },
                  "timer":{
                     "modules":{
                        
                     },
                     "types":{
                        "TimerNodeConfig":{
                           "constructors":{
                              "Json":"FromJson"
                           }
                        },
                        "PollTimer":{
                           "type_parameters":[
                              "U"
                           ],
                           "constructors":{
                              "New":{
                                 "New":{
                                    
                                 }
                              }
                           }
                        },
                        "SelectedTimer":{
                           "type_parameters":[
                              "U"
                           ],
                           "constructors":{
                              "New":{
                                 "New":{
                                    
                                 }
                              }
                           }
                        },
                        "TimerNode":{
                           "inputs":[
                              "config_input",
                              "token_input"
                           ],
                           "outputs":[
                              "token_output"
                           ],
                           "type_parameters":[
                              "T",
                              "U"
                           ],
                           "constructors":{
                              "NewWithToken":{
                                 "NewWithArbitraryArgs":{
                                    "function_name":"new_with_token",
                                    "arguments":[
                                       {
                                          "type":{
                                             "Generic":{
                                                "name":"T",
                                                "type_parameters":[
                                                   {
                                                      "Generic":{
                                                         "name":"U"
                                                      }
                                                   }
                                                ]
                                             }
                                          },
                                          "name":"timer",
                                          "passing":"Move",
                                          "construction":{
                                             "Constructor":"New"
                                          }
                                       },
                                       {
                                          "type":{
                                             "Generic":{
                                                "name":"U"
                                             }
                                          },
                                          "name":"token_object",
                                          "passing":"Move",
                                          "construction":{
                                             "Constructor":"New"
                                          }
                                       },
                                       {
                                          "type":{
                                             "Type":{
                                                "name":"()"
                                             }
                                          },
                                          "name":"change_observer",
                                          "passing":"Clone",
                                          "construction":{
                                             "ExistingObject":[
                                                
                                             ]
                                          }
                                       }
                                    ]
                                 }
                              },
                              "New":{
                                 "NewWithArbitraryArgs":{
                                    "arguments":[
                                       {
                                          "type":{
                                             "Generic":{
                                                "name":"T",
                                                "type_parameters":[
                                                   {
                                                      "Generic":{
                                                         "name":"U"
                                                      }
                                                   }
                                                ]
                                             }
                                          },
                                          "name":"timer",
                                          "passing":"Move",
                                          "construction":{
                                             "Constructor":"New"
                                          }
                                       },
                                       {
                                          "type":{
                                             "Type":{
                                                "name":"()"
                                             }
                                          },
                                          "name":"change_observer",
                                          "passing":"Clone",
                                          "construction":{
                                             "ExistingObject":[
                                                
                                             ]
                                          }
                                       }
                                    ]
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
}
Clone this wiki locally