pub fn from_json(obj: Json) -> Target {
        // this is 1. ugly, 2. error prone.


        let handler = diagnostic::default_handler(diagnostic::Auto, None, true);

        let get_req_field = |name: &str| {
            match obj.find(name)
                     .map(|s| s.as_string())
                     .and_then(|os| os.map(|s| s.to_string())) {
                Some(val) => val,
                None =>
                    handler.fatal(&format!("Field {} in target specification is required", name))
            }
        };

        let mut base = Target {
            data_layout: get_req_field("data-layout"),
            llvm_target: get_req_field("llvm-target"),
            target_endian: get_req_field("target-endian"),
            target_pointer_width: get_req_field("target-pointer-width"),
            arch: get_req_field("arch"),
            target_os: get_req_field("os"),
            target_env: obj.find("env").and_then(|s| s.as_string())
                           .map(|s| s.to_string()).unwrap_or(String::new()),
            options: Default::default(),
        };

        macro_rules! key {
            ($key_name:ident) => ( {
                let name = (stringify!($key_name)).replace("_", "-");
                obj.find(&name[..]).map(|o| o.as_string()
                                    .map(|s| base.options.$key_name = s.to_string()));
            } );
            ($key_name:ident, bool) => ( {
                let name = (stringify!($key_name)).replace("_", "-");
                obj.find(&name[..])
                    .map(|o| o.as_boolean()
                         .map(|s| base.options.$key_name = s));
            } );
            ($key_name:ident, list) => ( {
                let name = (stringify!($key_name)).replace("_", "-");
                obj.find(&name[..]).map(|o| o.as_array()
                    .map(|v| base.options.$key_name = v.iter()
                        .map(|a| a.as_string().unwrap().to_string()).collect()
                        )
                    );
            } );
        }

        key!(cpu);
        key!(linker);
        key!(relocation_model);
        key!(code_model);
        key!(dll_prefix);
        key!(dll_suffix);
        key!(exe_suffix);
        key!(staticlib_prefix);
        key!(staticlib_suffix);
        key!(features);
        key!(dynamic_linking, bool);
        key!(executables, bool);
        key!(morestack, bool);
        key!(disable_redzone, bool);
        key!(eliminate_frame_pointer, bool);
        key!(function_sections, bool);
        key!(is_like_osx, bool);
        key!(is_like_windows, bool);
        key!(linker_is_gnu, bool);
        key!(has_rpath, bool);
        key!(no_compiler_rt, bool);
        key!(pre_link_args, list);
        key!(post_link_args, list);

        base
    }
/// Load a target descriptor from a JSON object.
Load a target descriptor from a JSON object.
Load a target descriptor from a JSON object .
pub fn from_json(obj: Json) -> Target {
        // this is 1. ugly, 2. error prone.
        let handler = diagnostic::default_handler(diagnostic::Auto, None, true);
        let get_req_field = |name: &str| {
            match obj.find(name)
                     .map(|s| s.as_string())
                     .and_then(|os| os.map(|s| s.to_string())) {
                Some(val) => val,
                None =>
                    handler.fatal(&format!("Field {} in target specification is required", name))
            }
        };
        let mut base = Target {
            data_layout: get_req_field("data-layout"),
            llvm_target: get_req_field("llvm-target"),
            target_endian: get_req_field("target-endian"),
            target_pointer_width: get_req_field("target-pointer-width"),
            arch: get_req_field("arch"),
            target_os: get_req_field("os"),
            target_env: obj.find("env").and_then(|s| s.as_string())
                           .map(|s| s.to_string()).unwrap_or(String::new()),
            options: Default::default(),
        };
        macro_rules! key {
            ($key_name:ident) => ( {
                let name = (stringify!($key_name)).replace("_", "-");
                obj.find(&name[..]).map(|o| o.as_string()
                                    .map(|s| base.options.$key_name = s.to_string()));
            } );
            ($key_name:ident, bool) => ( {
                let name = (stringify!($key_name)).replace("_", "-");
                obj.find(&name[..])
                    .map(|o| o.as_boolean()
                         .map(|s| base.options.$key_name = s));
            } );
            ($key_name:ident, list) => ( {
                let name = (stringify!($key_name)).replace("_", "-");
                obj.find(&name[..]).map(|o| o.as_array()
                    .map(|v| base.options.$key_name = v.iter()
                        .map(|a| a.as_string().unwrap().to_string()).collect()
                        )
                    );
            } );
        }
        key!(cpu);
        key!(linker);
        key!(relocation_model);
        key!(code_model);
        key!(dll_prefix);
        key!(dll_suffix);
        key!(exe_suffix);
        key!(staticlib_prefix);
        key!(staticlib_suffix);
        key!(features);
        key!(dynamic_linking, bool);
        key!(executables, bool);
        key!(morestack, bool);
        key!(disable_redzone, bool);
        key!(eliminate_frame_pointer, bool);
        key!(function_sections, bool);
        key!(is_like_osx, bool);
        key!(is_like_windows, bool);
        key!(linker_is_gnu, bool);
        key!(has_rpath, bool);
        key!(no_compiler_rt, bool);
        key!(pre_link_args, list);
        key!(post_link_args, list);
        base
    }
pub fn from_json ( obj : Json ) -> Target { // this is 1. ugly, 2. error prone. let handler = diagnostic :: default_handler ( diagnostic :: Auto , None , true ) ; let get_req_field = | name : & str | { match obj . find ( name ) . map ( | s | s . as_string ( ) ) . and_then ( | os | os . map ( | s | s . to_string ( ) ) ) { Some ( val ) => val , None => handler . fatal ( & format ! ( " " name ) ) } } ; let mut base = Target { data_layout : get_req_field ( " " ) , llvm_target : get_req_field ( " " ) , target_endian : get_req_field ( " " ) , target_pointer_width : get_req_field ( " " ) , arch : get_req_field ( " " ) , target_os : get_req_field ( " " ) , target_env : obj . find ( " " ) . and_then ( | s | s . as_string ( ) ) . map ( | s | s . to_string ( ) ) . unwrap_or ( String :: new ( ) ) , options : Default :: default ( ) , } ; macro_rules! key { ( $key_name : ident ) => ( { let name ( stringify ( $key_name ) ) replace ( " " " " ) obj find ( name [ ] ) map ( o o as_string ( ) map ( s base options $key_name s to_string ( ) ) ) } ) ; ( $key_name : ident bool ) => ( { let name ( stringify ( $key_name ) ) replace ( " " " " ) obj find ( name [ ] ) map ( o o as_boolean ( ) map ( s base options $key_name s ) ) } ) ; ( $key_name : ident list ) => ( { let name ( stringify ( $key_name ) ) replace ( " " " " ) obj find ( name [ ] ) map ( o o as_array ( ) map ( v base options $key_name v iter ( ) map ( a a as_string ( ) unwrap ( ) to_string ( ) ) collect ( ) ) ) } ) ; } key ! ( cpu ) ; key ! ( linker ) ; key ! ( relocation_model ) ; key ! ( code_model ) ; key ! ( dll_prefix ) ; key ! ( dll_suffix ) ; key ! ( exe_suffix ) ; key ! ( staticlib_prefix ) ; key ! ( staticlib_suffix ) ; key ! ( features ) ; key ! ( dynamic_linking bool ) ; key ! ( executables bool ) ; key ! ( morestack bool ) ; key ! ( disable_redzone bool ) ; key ! ( eliminate_frame_pointer bool ) ; key ! ( function_sections bool ) ; key ! ( is_like_osx bool ) ; key ! ( is_like_windows bool ) ; key ! ( linker_is_gnu bool ) ; key ! ( has_rpath bool ) ; key ! ( no_compiler_rt bool ) ; key ! ( pre_link_args list ) ; key ! ( post_link_args list ) ; base }
Load a target descriptor from a JSON object.
Load a target descriptor from a JSON object .
obj
Json