Reader small image

You're reading from  Network Programming with Rust

Product typeBook
Published inFeb 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788624893
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Abhishek Chanda
Abhishek Chanda
author image
Abhishek Chanda

Abhishek Chanda studied computer science at IIEST Shibpur in India and electrical engineering at Rutgers University. He has been working on networking and distributed systems since 2008. Over his career, he has worked with large companies (like Microsoft and Dell) and small startups (Cloudscaling, DataSine) in India, US, and the UK. He is enthusiastic about open source software and has contributed to a number of projects like OpenStack, Nomad etc. He contributes to a number of open source projects. He came across Rust in 2015 and found it to be a perfect fit for writing highly performant systems.
Read more about Abhishek Chanda

Right arrow

Generics and the trait system

Rust supports writing generic code that is later bound with more concrete types, either during compile time or during runtime. People who are familiar with templates in C++ might notice that generics in Rust are pretty similar to templates, as far as syntax goes. The following example illustrates how to use generic programming. We also introduce some new constructs which we haven't discussed before, which we will explain as we proceed.

Much like C and C++, a Rust struct defines a user-defined type that aggregates multiple logically connected resources in one unit. Our struct here defines a tuple of two variables. We define a generic struct and we use a generic type parameter, written here as <T>. Each member of the struct is defined to be of that type. We later define a generic function that sums the two elements of the tuple. Let&apos...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Network Programming with Rust
Published in: Feb 2018Publisher: PacktISBN-13: 9781788624893

Author (1)

author image
Abhishek Chanda

Abhishek Chanda studied computer science at IIEST Shibpur in India and electrical engineering at Rutgers University. He has been working on networking and distributed systems since 2008. Over his career, he has worked with large companies (like Microsoft and Dell) and small startups (Cloudscaling, DataSine) in India, US, and the UK. He is enthusiastic about open source software and has contributed to a number of projects like OpenStack, Nomad etc. He contributes to a number of open source projects. He came across Rust in 2015 and found it to be a perfect fit for writing highly performant systems.
Read more about Abhishek Chanda