Skip to content

&static str #407

Open
Open
@wangjiawen2013

Description

@wangjiawen2013

Hi,
The following code is a common way to return value:

fn parse_version(header: &[u8]) -> Result<Version, &'static str> {
    match header.get(0) {
        None => Err("invalid header length"),
        Some(&1) => Ok(Version::Version1),
        Some(&2) => Ok(Version::Version2),
        Some(_) => Err("invalid version"),
    }
}

By this way, the error will be returned as a &'static str and we can return any errors with this way, what's the advantage of thiserror over &'static str?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions