Skip to content

File::set_len uses an immutable reference to self #47708

Closed
@vitiral

Description

@vitiral

I am creating a wrapper for the File type and came across an issue that I thought was odd.

Both of these methods take an immutable reference (&self) to the File instead of a mutable reference (&mut self).

I'm not so much concerned about memory safety per se, as I assume that the operating system guarantees that operaions are memory safe, it is just that this is extremely unexpected. If I pass a function an immutable reference to a File, I wouldn't expect it to be able to truncate the file!

Obviously this is a breaking change so probably can't be changed -- however, I was thinking we could at least add docs explaining why the reference is immutable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions