Skip to content

Mistake in CStr type's to_string_lossy() doc #139835

Closed
@jnqnfe

Description

@jnqnfe

Location

https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.to_str

Summary

The documentation for the to_string_lossy() method of CStr, which returns a Cow<'_, str>, currently contains the following text:

If the contents of the CStr are valid UTF-8 data, this function will return a Cow::Borrowed(&str) with the corresponding &str slice. Otherwise, it will replace any invalid UTF-8 sequences with U+FFFD REPLACEMENT CHARACTER and return a Cow::Owned(&str) with the result.

The owned case seems wrong. I believe that it would return a Cow::Owned(String) not a Cow::Owned(&str).

The documentation did actually claim Cow::Owned(String) was returned prior to commit 67065fe which changed it to the above without explanation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library 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