fn convert_to_fidl_constant(
    declaration: bind_library::Declaration,
    path: &String,
) -> Result<String, Error> {
    let mut result = String::new();
    let identifier_name = declaration.identifier.name.to_uppercase();

    // Generating the key definition is only done when it is not extended.
    // When it is extended, the key will already be defined in the library that it is
    // extending from.
    if !declaration.extends {
        writeln!(
            &mut result,
            "const fdf.NodePropertyKey {} = \"{}.{}\";",
            &identifier_name, &path, &identifier_name
        )?;
    }

    for value in &declaration.values {
        let name = generate_declaration_name(&identifier_name, value);
        let property_output = match &value {
            bind_library::Value::Number(_, val) => {
                format!("const fdf.NodePropertyValueUint {} = {};", name, val)
            }
            bind_library::Value::Str(_, val) => {
                format!("const fdf.NodePropertyValueString {} = \"{}\";", name, val)
            }
            bind_library::Value::Bool(_, val) => {
                format!("const fdf.NodePropertyValueBool {} = {};", name, val)
            }
            bind_library::Value::Enum(_) => {
                format!("const fdf.NodePropertyValueEnum {};", name)
            }
        };
        writeln!(&mut result, "{}", property_output)?;
    }

    Ok(result)
}
/// Converts a declaration to the FIDL constant format.
Converts a declaration to the FIDL constant format.
Converts a declaration to the FIDL constant format .
fn convert_to_fidl_constant(
    declaration: bind_library::Declaration,
    path: &String,
) -> Result<String, Error> {
    let mut result = String::new();
    let identifier_name = declaration.identifier.name.to_uppercase();
    // Generating the key definition is only done when it is not extended.
    // When it is extended, the key will already be defined in the library that it is
    // extending from.
    if !declaration.extends {
        writeln!(
            &mut result,
            "const fdf.NodePropertyKey {} = \"{}.{}\";",
            &identifier_name, &path, &identifier_name
        )?;
    }
    for value in &declaration.values {
        let name = generate_declaration_name(&identifier_name, value);
        let property_output = match &value {
            bind_library::Value::Number(_, val) => {
                format!("const fdf.NodePropertyValueUint {} = {};", name, val)
            }
            bind_library::Value::Str(_, val) => {
                format!("const fdf.NodePropertyValueString {} = \"{}\";", name, val)
            }
            bind_library::Value::Bool(_, val) => {
                format!("const fdf.NodePropertyValueBool {} = {};", name, val)
            }
            bind_library::Value::Enum(_) => {
                format!("const fdf.NodePropertyValueEnum {};", name)
            }
        };
        writeln!(&mut result, "{}", property_output)?;
    }
    Ok(result)
}
fn convert_to_fidl_constant ( declaration : bind_library :: Declaration , path : & String , ) -> Result < String , Error > { let mut result = String :: new ( ) ; let identifier_name = declaration . identifier . name . to_uppercase ( ) ; // Generating the key definition is only done when it is not extended. // When it is extended, the key will already be defined in the library that it is // extending from. if ! declaration . extends { writeln ! ( mut result " \" \" " identifier_name path identifier_name ) ? ; } for value in & declaration . values { let name = generate_declaration_name ( & identifier_name , value ) ; let property_output = match & value { bind_library :: Value :: Number ( _ , val ) => { format ! ( " " name val ) } bind_library :: Value :: Str ( _ , val ) => { format ! ( " \" \" " name val ) } bind_library :: Value :: Bool ( _ , val ) => { format ! ( " " name val ) } bind_library :: Value :: Enum ( _ ) => { format ! ( " " name ) } } ; writeln ! ( mut result " " property_output ) ? ; } Ok ( result ) }
Converts a declaration to the FIDL constant format.
Converts a declaration to the FIDL constant format .
declaration
bind_library::Declaration
path
&String
declaration
bind_library::Declaration
path
&String