Can we make things safer?

There is a strategy that we can take to try and make things slightly safer.

Consider our original extern code:

[link(name="mathlib")] 
extern 
 { 
     fn add_two_int_numbers(a: i32, b: i32) -> i32; 
} 

This code is calling a raw C API and, as discussed, any calls to this have to be marked as being unsafe. It is unsafe as the call is known as being low level.

In terms of programming languages, the lower the language, the closer it is to being a language understood by the processor (an assembler is considered the lowest language that is of any real use, short of poking raw binary into a memory location). Here we are exposing the library at its lowest level.

In order to make the call safer, we use something known as wrapping.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset