Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 1.09 KB

03-function.mdx

File metadata and controls

27 lines (18 loc) · 1.09 KB
title
Function

Example of function.

import CodeBlock from '@theme/CodeBlock'; import func from '!!raw-loader!/src/03-function/main.rs';

{func}

:::danger

In the above example, ff we assign x, and y both to be 2147483647 (max i32), the result will overflow i32 range. Unfortunately, such errors are not caught compile time.

Check out helper methods: wrapping_add, saturating_add, overflowing_add, checked_add.

:::

Calculate area of a circle

Another example where we calculate area of a circle with the input radius given by the user.

import circle_area from '!!raw-loader!/src/03-circle-area/main.rs';

{circle_area}