Impl

The impl keyword works in a very similar way to a function. The structure of an implementation needs to considered as being closer to a static class (in C#) or as a function within a function:

impl MyImpl
{
fn reference_name (&self) ...
}

This would be more for a non-generic type. For generics, the preceding code becomes the following:

impl <T> MyGenericImpl<T>
{
fn reference_name(&self) ...
}

Note that the <T> is required to tell the compiler that the impl is for a generic. reference_name is the name used to access the impl function. It can be anything you wish.

An example of impl can be found in 09/impl_example.

If you build and run the impl_example code, you will get a result like this:

The code creates two implementations for two functions that provide a defined functionality.

The impl_example is a very simple example. An impl can be as complex as required.

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

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