| minutes | 2 |
|---|
A constructor function, strongly implying "type conversion".
# // Copyright 2025 Google LLC
# // SPDX-License-Identifier: Apache-2.0
#
impl Duration {
fn from_days(days: u64) -> Duration;
}
impl i32 {
fn from_ascii(src: &[u8]) -> Result<i32, ParseIntError>;
}
impl u32 {
fn from_le_bytes(bytes: [u8; 4]) -> u32;
}Details
-
Prefix for constructor-style,
From-trait-style functions. -
These functions can take multiple arguments, but usually imply the user is doing more of the work than a usual constructor would.
-
newis still preferred for most constructor-style functions, the implication forfromis transformation of one data type to another.