Skip to content

FromStr is not implemented for char #24939

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),
        }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions