Skip to content

Tracking issue for the convert::FloatToInt trait #67057

Open
@SimonSapin

Description

@SimonSapin

PR #66841 adds this supporting trait for the {f32,f64}::approx_unchecked_to method (tracking issue: #67058) to the core::convert and std::convert modules:

mod private {
    pub trait Sealed {}
}
pub trait FloatToInt<Int>: private::Sealed + Sized {
    #[doc(hidden)]
    unsafe fn approx_unchecked(self) -> Int;
}

// Macro-generated for all combinations of primitive integer
// and primitive floating point types:
impl FloatToInt<$Int> for $Float {}

The name and location (and usage of the sealed-trait pattern) are chosen to allow later adding additional methods with different conversion semantics between those types, as proposed in https://internals.rust-lang.org/t/pre-rfc-add-explicitly-named-numeric-conversion-apis/11395

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-floating-pointArea: Floating point numbers and arithmeticB-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.S-tracking-perma-unstableStatus: The feature will stay unstable indefinitely.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions