Abstract
Rust performs a strict data type check, so when you define a function that uses an argument of a certain type, say fn square_root(x: f32) -> f32, the code that invokes such a function must pass to it an expression of exactly that type, like in square_root(45.2f32), or it must perform explicit conversions every time that function is used, like in square_root(45.2f64 as f32). You cannot pass a different type, like in square_root(45.2f64).
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsAuthor information
Authors and Affiliations
Rights and permissions
Copyright information
© 2018 Carlo Milanesi
About this chapter
Cite this chapter
Milanesi, C. (2018). Defining Generic Functions and Structs. In: Beginning Rust. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-3468-6_10
Download citation
DOI: https://doi.org/10.1007/978-1-4842-3468-6_10
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-3467-9
Online ISBN: 978-1-4842-3468-6
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books