pub fn codepoint_to_codepoint_fn(
        &mut self,
        name: &str,
        map: &BTreeMap<u32, u32>,
    ) -> Result<()> {
        self.header()?;
        self.separator()?;

        writeln!(self.wtr, "use std::num::NonZeroU32;")?;
        self.separator()?;

        let fn_name = rust_fn_name(name);
        writeln!(
            self.wtr,
            "pub fn {}(cp: u32) -> Option<NonZeroU32> {{",
            fn_name
        )?;
        self.wtr.indent("    ");
        self.wtr.write_str(
            "// new_unchecked is safe as ucd-generate checks \
             that the destination",
        )?;
        self.wtr.flush_line()?;
        self.wtr.write_str(
            "// codepoint is non-zero at \
             code generation time.",
        )?;
        self.wtr.flush_line()?;
        self.wtr.write_str("unsafe {")?;
        self.wtr.flush_line()?;
        self.wtr.indent("        ");
        self.wtr.write_str("match cp {")?;
        self.wtr.flush_line()?;
        self.wtr.indent("            ");
        for (from, to) in map {
            if *to == 0 {
                return err!(
                    "destination codepoint must not be 0 (NUL) for \
                     rust-match output format"
                );
            }
            self.wtr.write_str(&format!(
                "{} => Some(NonZeroU32::new_unchecked({})),",
                from, to
            ))?;
            self.wtr.flush_line()?;
        }
        self.wtr.write_str("_ => None,")?;
        self.wtr.flush_line()?;
        self.wtr.indent("        ");
        self.wtr.write_str("}")?;
        self.wtr.flush_line()?;
        self.wtr.indent("    ");
        self.wtr.write_str("}")?;
        self.wtr.flush_line()?;
        writeln!(self.wtr, "}}")?;
        self.wtr.flush()?;
        Ok(())
    }
/// Write a function that associates codepoints with other codepoints.
///
/// The function will use a match expression to map between codepoints.
/// The fallback branch of the match returns 0.
Write a function that associates codepoints with other codepoints.
The function will use a match expression to map between codepoints.
The fallback branch of the match returns 0.
Write a function that associates codepoints with other codepoints . The function will use a match expression to map between codepoints . The fallback branch of the match returns 0 .
pub fn codepoint_to_codepoint_fn(
        &mut self,
        name: &str,
        map: &BTreeMap<u32, u32>,
    ) -> Result<()> {
        self.header()?;
        self.separator()?;
        writeln!(self.wtr, "use std::num::NonZeroU32;")?;
        self.separator()?;
        let fn_name = rust_fn_name(name);
        writeln!(
            self.wtr,
            "pub fn {}(cp: u32) -> Option<NonZeroU32> {{",
            fn_name
        )?;
        self.wtr.indent("    ");
        self.wtr.write_str(
            "// new_unchecked is safe as ucd-generate checks \
             that the destination",
        )?;
        self.wtr.flush_line()?;
        self.wtr.write_str(
            "// codepoint is non-zero at \
             code generation time.",
        )?;
        self.wtr.flush_line()?;
        self.wtr.write_str("unsafe {")?;
        self.wtr.flush_line()?;
        self.wtr.indent("        ");
        self.wtr.write_str("match cp {")?;
        self.wtr.flush_line()?;
        self.wtr.indent("            ");
        for (from, to) in map {
            if *to == 0 {
                return err!(
                    "destination codepoint must not be 0 (NUL) for \
                     rust-match output format"
                );
            }
            self.wtr.write_str(&format!(
                "{} => Some(NonZeroU32::new_unchecked({})),",
                from, to
            ))?;
            self.wtr.flush_line()?;
        }
        self.wtr.write_str("_ => None,")?;
        self.wtr.flush_line()?;
        self.wtr.indent("        ");
        self.wtr.write_str("}")?;
        self.wtr.flush_line()?;
        self.wtr.indent("    ");
        self.wtr.write_str("}")?;
        self.wtr.flush_line()?;
        writeln!(self.wtr, "}}")?;
        self.wtr.flush()?;
        Ok(())
    }
pub fn codepoint_to_codepoint_fn ( & mut self , name : & str , map : & BTreeMap < u32 , u32 > , ) -> Result < ( ) > { self . header ( ) ? ; self . separator ( ) ? ; writeln ! ( self wtr " " ) ? ; self . separator ( ) ? ; let fn_name = rust_fn_name ( name ) ; writeln ! ( self wtr " " fn_name ) ? ; self . wtr . indent ( " " ) ; self . wtr . write_str ( " \
 " , ) ? ; self . wtr . flush_line ( ) ? ; self . wtr . write_str ( " \
 " , ) ? ; self . wtr . flush_line ( ) ? ; self . wtr . write_str ( " " ) ? ; self . wtr . flush_line ( ) ? ; self . wtr . indent ( " " ) ; self . wtr . write_str ( " " ) ? ; self . wtr . flush_line ( ) ? ; self . wtr . indent ( " " ) ; for ( from , to ) in map { if * to == 0 { return err ! ( " \
 " ) ; } self . wtr . write_str ( & format ! ( " " from to ) ) ? ; self . wtr . flush_line ( ) ? ; } self . wtr . write_str ( " " ) ? ; self . wtr . flush_line ( ) ? ; self . wtr . indent ( " " ) ; self . wtr . write_str ( " " ) ? ; self . wtr . flush_line ( ) ? ; self . wtr . indent ( " " ) ; self . wtr . write_str ( " " ) ? ; self . wtr . flush_line ( ) ? ; writeln ! ( self wtr " " ) ? ; self . wtr . flush ( ) ? ; Ok ( ( ) ) }
Write a function that associates codepoints with other codepoints.
Write a function that associates codepoints with other codepoints .
&mut self
name
&str
map
&BTreeMap<u32, u32>
&mut self
name
&str
map
&BTreeMap<u32, u32>