Function try_parse_from_file

Source
pub fn try_parse_from_file<N>(
    path: impl AsRef<Path>,
    vars: Vars,
) -> Result<(N, Vars)>
where N: for<'a> Deserialize<'a>,
Expand description

Attempts to parse an instance of N from the content of the file located at path, overwriting (or complementing) the Vars declared in said file with the provided vars.

This function is notably used to parse a data flow descriptor. Two file types are supported, identified by their extension:

  • JSON (.json file extension)
  • YAML (.yaml or .yml extensions)

This function does not impose writing all descriptor file(s), within the same data flow, in the same format.

§Errors

The parsing can fail for several reasons (listed in sequential order):

  • the OS failed to canonicalize the path of the file,
  • the OS failed to open (in read mode) the file,
  • the extension of the file is not supported by Zenoh-Flow (i.e. it’s neither a YAML file or a JSON file),
  • parsing the Vars section failed (if there is one),
  • expanding the variables located in the Vars section failed (if there are any) — see the documentation handlebars for a more complete list of reasons,
  • parsing an instance of N failed.