Skip to content

FromStr is not implemented for char #24939

Closed
@oli-obk

Description

@oli-obk

I'm not sure if this is an oversight. But the implementation should be trivial. I'll add tests and implement it, if it is fine.

enum ParseCharError { EmptyString, TooManyChars }
impl FromStr for char {
    type Err = ParseCharError;
    #[inline]
    fn from_str(s: &str) -> Result<char, ParseCharError> {
        match s.len() {
            0 => Err(ParseCharError::EmptyString),
            1 => Ok(s[0]),
            _ => Err(ParseCharError::TooManyChars),
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    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