File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -2930,6 +2930,7 @@ effects of the expression's evaluation.
2930
2930
* Ref.Expr.Ret :: Expression for stopping and producing a value.
2931
2931
@c * Ref.Expr.Be:: Expression for stopping and executing a tail call.
2932
2932
* Ref.Expr.Put :: Expression for pausing and producing a value.
2933
+ * Ref.Expr.As :: Expression for casting a value to a different type.
2933
2934
* Ref.Expr.Fail :: Expression for causing task failure.
2934
2935
* Ref.Expr.Log :: Expression for logging values to diagnostic buffers.
2935
2936
* Ref.Expr.Note :: Expression for logging values during failure.
@@ -3116,6 +3117,30 @@ either continuing execution after the @code{put} expression, or terminating its
3116
3117
execution and destroying the iterator frame.
3117
3118
3118
3119
3120
+ @node Ref.Expr.As
3121
+ @subsection Ref.Expr.As
3122
+ @c * Ref.Expr.As:: Expression for casting a value to a different type.
3123
+ @cindex As expression
3124
+ @cindex Cast
3125
+ @cindex Typecast
3126
+
3127
+ Executing an @code {as } expression casts the value on the left-hand side to the
3128
+ type on the right-hand side.
3129
+
3130
+ A numeric value can be cast to any numeric type. A native pointer value can
3131
+ be cast to or from any integral type or native pointer type. Any other cast
3132
+ is unsupported and will fail to compile.
3133
+
3134
+ An example of an @code {as } expression:
3135
+ @example
3136
+ fn avg(v: [float]) -> float @{
3137
+ let sum: float = sum(v);
3138
+ let sz: float = std::vec::len(v) as float;
3139
+ ret sum / sz;
3140
+ @}
3141
+ @end example
3142
+
3143
+
3119
3144
@node Ref.Expr.Fail
3120
3145
@subsection Ref.Expr.Fail
3121
3146
@c * Ref.Expr.Fail:: Expression for causing task failure.
You can’t perform that action at this time.
0 commit comments